Skip to content

Commit 879b08e

Browse files
rekram1-nodeschneiderlo
authored andcommitted
fix: ensure vercel variants pass amazon models under bedrock key (anomalyco#13631)
1 parent e5a7484 commit 879b08e

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

packages/opencode/src/provider/transform.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,22 @@ export namespace ProviderTransform {
802802
return {}
803803
}
804804

805+
// Maps model ID prefix to provider slug used in providerOptions.
806+
// Example: "amazon/nova-2-lite" → "bedrock"
807+
const SLUG_OVERRIDES: Record<string, string> = {
808+
amazon: "bedrock",
809+
}
810+
805811
export function providerOptions(model: Provider.Model, options: { [x: string]: any }) {
806812
if (model.api.npm === "@ai-sdk/gateway") {
807813
// Gateway providerOptions are split across two namespaces:
808-
// - `gateway`: gateway-native routing/caching controls
814+
// - `gateway`: gateway-native routing/caching controls (order, only, byok, etc.)
809815
// - `<upstream slug>`: provider-specific model options (anthropic/openai/...)
810816
// We keep `gateway` as-is and route every other top-level option under the
811-
// model-derived upstream slug so variants/options can stay flat internally.
817+
// model-derived upstream slug.
812818
const i = model.api.id.indexOf("/")
813-
const slug = i > 0 ? model.api.id.slice(0, i) : undefined
819+
const rawSlug = i > 0 ? model.api.id.slice(0, i) : undefined
820+
const slug = rawSlug ? (SLUG_OVERRIDES[rawSlug] ?? rawSlug) : undefined
814821
const gateway = options.gateway
815822
const rest = Object.fromEntries(Object.entries(options).filter(([k]) => k !== "gateway"))
816823
const has = Object.keys(rest).length > 0
@@ -820,6 +827,7 @@ export namespace ProviderTransform {
820827

821828
if (has) {
822829
if (slug) {
830+
// Route model-specific options under the provider slug
823831
result[slug] = rest
824832
} else if (gateway && typeof gateway === "object" && !Array.isArray(gateway)) {
825833
result.gateway = { ...gateway, ...rest }

packages/opencode/test/provider/transform.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,36 @@ describe("ProviderTransform.providerOptions", () => {
341341
gateway: { reasoningEffort: "high" },
342342
})
343343
})
344+
345+
test("maps amazon slug to bedrock for provider options", () => {
346+
const model = createModel({
347+
providerID: "vercel",
348+
api: {
349+
id: "amazon/nova-2-lite",
350+
url: "https://ai-gateway.vercel.sh/v3/ai",
351+
npm: "@ai-sdk/gateway",
352+
},
353+
})
354+
355+
expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({
356+
bedrock: { reasoningConfig: { type: "enabled" } },
357+
})
358+
})
359+
360+
test("uses groq slug for groq models", () => {
361+
const model = createModel({
362+
providerID: "vercel",
363+
api: {
364+
id: "groq/llama-3.3-70b-versatile",
365+
url: "https://ai-gateway.vercel.sh/v3/ai",
366+
npm: "@ai-sdk/gateway",
367+
},
368+
})
369+
370+
expect(ProviderTransform.providerOptions(model, { reasoningFormat: "parsed" })).toEqual({
371+
groq: { reasoningFormat: "parsed" },
372+
})
373+
})
344374
})
345375

346376
describe("ProviderTransform.schema - gemini array items", () => {

0 commit comments

Comments
 (0)