feat(llm): resolve Azure provider natively

This commit is contained in:
Kit Langton
2026-04-28 09:27:24 -04:00
parent 7141036ec4
commit f2f7a338de
11 changed files with 137 additions and 21 deletions
@@ -1,6 +1,7 @@
import {
AmazonBedrock,
Anthropic,
Azure,
GitHubCopilot,
Google,
LLM,
@@ -27,6 +28,7 @@ type Input = {
const PROVIDERS: Record<string, ProviderResolverShape> = {
"@ai-sdk/amazon-bedrock": AmazonBedrock.resolver,
"@ai-sdk/anthropic": Anthropic.resolver,
"@ai-sdk/azure": Azure.resolver,
"@ai-sdk/baseten": OpenAICompatibleFamily.resolver,
"@ai-sdk/cerebras": OpenAICompatibleFamily.resolver,
"@ai-sdk/deepinfra": OpenAICompatibleFamily.resolver,
@@ -144,6 +146,7 @@ export const toModelRef = (input: Input): ModelRef | undefined => {
opencodeProviderID: input.provider.id,
opencodeModelID: input.model.id,
npm: input.model.api.npm,
...(resolution.queryParams ? { queryParams: resolution.queryParams } : {}),
},
})
}
@@ -106,7 +106,7 @@ describe("ProviderLLMBridge", () => {
})
})
test("maps GitHub Copilot through its provider route", () => {
test("maps GitHub Copilot through its provider resolver", () => {
const ref = ProviderLLMBridge.toModelRef({
provider: provider({ id: ProviderID.make("github-copilot"), key: "copilot-key" }),
model: model({ id: "gpt-5", providerID: "github-copilot", npm: "@ai-sdk/github-copilot" }),
@@ -119,6 +119,39 @@ describe("ProviderLLMBridge", () => {
})
})
test("maps Azure to Responses with resource URL and api-version query", () => {
const ref = ProviderLLMBridge.toModelRef({
provider: provider({
id: ProviderID.make("azure"),
key: "azure-key",
options: { resourceName: "opencode-test", apiVersion: "2025-04-01-preview" },
}),
model: model({ id: "gpt-5", providerID: "azure", npm: "@ai-sdk/azure" }),
})
expect(ref).toMatchObject({
provider: "azure",
protocol: "openai-responses",
baseURL: "https://opencode-test.openai.azure.com/openai/v1",
headers: { authorization: "Bearer azure-key" },
native: { queryParams: { "api-version": "2025-04-01-preview" } },
})
})
test("maps Azure completion URL opt-in to Chat Completions", () => {
const ref = ProviderLLMBridge.toModelRef({
provider: provider({ id: ProviderID.make("azure"), key: "azure-key", options: { resourceName: "opencode-test" } }),
model: model({ id: "gpt-4.1", providerID: "azure", npm: "@ai-sdk/azure", options: { useCompletionUrls: true } }),
})
expect(ref).toMatchObject({
provider: "azure",
protocol: "openai-chat",
baseURL: "https://opencode-test.openai.azure.com/openai/v1",
native: { queryParams: { "api-version": "v1" } },
})
})
test("keeps provider and model overrides ahead of defaults", () => {
const ref = ProviderLLMBridge.toModelRef({
provider: provider({
@@ -170,7 +203,6 @@ describe("ProviderLLMBridge", () => {
test("leaves undecided provider packages unmapped", () => {
const unsupported = [
["mistral", "mistral-large", "@ai-sdk/mistral"],
["azure", "gpt-4.1", "@ai-sdk/azure"],
] as const
expect(