fix vercel gateway variants (#13541)
Co-authored-by: Benjamin Woodruff <github@benjam.info>"
This commit is contained in:
@@ -175,6 +175,174 @@ describe("ProviderTransform.options - gpt-5 textVerbosity", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.options - gateway", () => {
|
||||
const sessionID = "test-session-123"
|
||||
|
||||
const createModel = (id: string) =>
|
||||
({
|
||||
id,
|
||||
providerID: "vercel",
|
||||
api: {
|
||||
id,
|
||||
url: "https://ai-gateway.vercel.sh/v3/ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
name: id,
|
||||
capabilities: {
|
||||
temperature: true,
|
||||
reasoning: true,
|
||||
attachment: true,
|
||||
toolcall: true,
|
||||
input: { text: true, audio: false, image: true, video: false, pdf: true },
|
||||
output: { text: true, audio: false, image: false, video: false, pdf: false },
|
||||
interleaved: false,
|
||||
},
|
||||
cost: {
|
||||
input: 0.001,
|
||||
output: 0.002,
|
||||
cache: { read: 0.0001, write: 0.0002 },
|
||||
},
|
||||
limit: {
|
||||
context: 200_000,
|
||||
output: 8192,
|
||||
},
|
||||
status: "active",
|
||||
options: {},
|
||||
headers: {},
|
||||
release_date: "2024-01-01",
|
||||
}) as any
|
||||
|
||||
test("puts gateway defaults under gateway key", () => {
|
||||
const model = createModel("anthropic/claude-sonnet-4")
|
||||
const result = ProviderTransform.options({ model, sessionID, providerOptions: {} })
|
||||
expect(result).toEqual({
|
||||
gateway: {
|
||||
caching: "auto",
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.providerOptions", () => {
|
||||
const createModel = (overrides: Partial<any> = {}) =>
|
||||
({
|
||||
id: "test/test-model",
|
||||
providerID: "test",
|
||||
api: {
|
||||
id: "test-model",
|
||||
url: "https://api.test.com",
|
||||
npm: "@ai-sdk/openai",
|
||||
},
|
||||
name: "Test Model",
|
||||
capabilities: {
|
||||
temperature: true,
|
||||
reasoning: true,
|
||||
attachment: true,
|
||||
toolcall: true,
|
||||
input: { text: true, audio: false, image: true, video: false, pdf: false },
|
||||
output: { text: true, audio: false, image: false, video: false, pdf: false },
|
||||
interleaved: false,
|
||||
},
|
||||
cost: {
|
||||
input: 0.001,
|
||||
output: 0.002,
|
||||
cache: { read: 0.0001, write: 0.0002 },
|
||||
},
|
||||
limit: {
|
||||
context: 200_000,
|
||||
output: 64_000,
|
||||
},
|
||||
status: "active",
|
||||
options: {},
|
||||
headers: {},
|
||||
release_date: "2024-01-01",
|
||||
...overrides,
|
||||
}) as any
|
||||
|
||||
test("uses sdk key for non-gateway models", () => {
|
||||
const model = createModel({
|
||||
providerID: "my-bedrock",
|
||||
api: {
|
||||
id: "anthropic.claude-sonnet-4",
|
||||
url: "https://bedrock.aws",
|
||||
npm: "@ai-sdk/amazon-bedrock",
|
||||
},
|
||||
})
|
||||
|
||||
expect(ProviderTransform.providerOptions(model, { cachePoint: { type: "default" } })).toEqual({
|
||||
bedrock: { cachePoint: { type: "default" } },
|
||||
})
|
||||
})
|
||||
|
||||
test("uses gateway model provider slug for gateway models", () => {
|
||||
const model = createModel({
|
||||
providerID: "vercel",
|
||||
api: {
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
url: "https://ai-gateway.vercel.sh/v3/ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
})
|
||||
|
||||
expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
|
||||
anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
|
||||
})
|
||||
})
|
||||
|
||||
test("falls back to gateway key when gateway api id is unscoped", () => {
|
||||
const model = createModel({
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
providerID: "vercel",
|
||||
api: {
|
||||
id: "claude-sonnet-4",
|
||||
url: "https://ai-gateway.vercel.sh/v3/ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
})
|
||||
|
||||
expect(ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 12_000 } })).toEqual({
|
||||
gateway: { thinking: { type: "enabled", budgetTokens: 12_000 } },
|
||||
})
|
||||
})
|
||||
|
||||
test("splits gateway routing options from provider-specific options", () => {
|
||||
const model = createModel({
|
||||
providerID: "vercel",
|
||||
api: {
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
url: "https://ai-gateway.vercel.sh/v3/ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
})
|
||||
|
||||
expect(
|
||||
ProviderTransform.providerOptions(model, {
|
||||
gateway: { order: ["vertex", "anthropic"] },
|
||||
thinking: { type: "enabled", budgetTokens: 12_000 },
|
||||
}),
|
||||
).toEqual({
|
||||
gateway: { order: ["vertex", "anthropic"] },
|
||||
anthropic: { thinking: { type: "enabled", budgetTokens: 12_000 } },
|
||||
} as any)
|
||||
})
|
||||
|
||||
test("falls back to gateway key when model id has no provider slug", () => {
|
||||
const model = createModel({
|
||||
id: "claude-sonnet-4",
|
||||
providerID: "vercel",
|
||||
api: {
|
||||
id: "claude-sonnet-4",
|
||||
url: "https://ai-gateway.vercel.sh/v3/ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
})
|
||||
|
||||
expect(ProviderTransform.providerOptions(model, { reasoningEffort: "high" })).toEqual({
|
||||
gateway: { reasoningEffort: "high" },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.schema - gemini array items", () => {
|
||||
test("adds missing items for array properties", () => {
|
||||
const geminiModel = {
|
||||
@@ -1232,6 +1400,105 @@ describe("ProviderTransform.message - claude w/bedrock custom inference profile"
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.message - cache control on gateway", () => {
|
||||
const createModel = (overrides: Partial<any> = {}) =>
|
||||
({
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
providerID: "vercel",
|
||||
api: {
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
url: "https://ai-gateway.vercel.sh/v3/ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
name: "Claude Sonnet 4",
|
||||
capabilities: {
|
||||
temperature: true,
|
||||
reasoning: true,
|
||||
attachment: true,
|
||||
toolcall: true,
|
||||
input: { text: true, audio: false, image: true, video: false, pdf: true },
|
||||
output: { text: true, audio: false, image: false, video: false, pdf: false },
|
||||
interleaved: false,
|
||||
},
|
||||
cost: { input: 0.001, output: 0.002, cache: { read: 0.0001, write: 0.0002 } },
|
||||
limit: { context: 200_000, output: 8192 },
|
||||
status: "active",
|
||||
options: {},
|
||||
headers: {},
|
||||
...overrides,
|
||||
}) as any
|
||||
|
||||
test("gateway does not set cache control for anthropic models", () => {
|
||||
const model = createModel()
|
||||
const msgs = [
|
||||
{
|
||||
role: "system",
|
||||
content: [{ type: "text", text: "You are a helpful assistant" }],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: "Hello",
|
||||
},
|
||||
] as any[]
|
||||
|
||||
const result = ProviderTransform.message(msgs, model, {}) as any[]
|
||||
|
||||
expect(result[0].content[0].providerOptions).toBeUndefined()
|
||||
expect(result[0].providerOptions).toBeUndefined()
|
||||
})
|
||||
|
||||
test("non-gateway anthropic keeps existing cache control behavior", () => {
|
||||
const model = createModel({
|
||||
providerID: "anthropic",
|
||||
api: {
|
||||
id: "claude-sonnet-4",
|
||||
url: "https://api.anthropic.com",
|
||||
npm: "@ai-sdk/anthropic",
|
||||
},
|
||||
})
|
||||
const msgs = [
|
||||
{
|
||||
role: "system",
|
||||
content: "You are a helpful assistant",
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: "Hello",
|
||||
},
|
||||
] as any[]
|
||||
|
||||
const result = ProviderTransform.message(msgs, model, {}) as any[]
|
||||
|
||||
expect(result[0].providerOptions).toEqual({
|
||||
anthropic: {
|
||||
cacheControl: {
|
||||
type: "ephemeral",
|
||||
},
|
||||
},
|
||||
openrouter: {
|
||||
cacheControl: {
|
||||
type: "ephemeral",
|
||||
},
|
||||
},
|
||||
bedrock: {
|
||||
cachePoint: {
|
||||
type: "default",
|
||||
},
|
||||
},
|
||||
openaiCompatible: {
|
||||
cache_control: {
|
||||
type: "ephemeral",
|
||||
},
|
||||
},
|
||||
copilot: {
|
||||
copilot_cache_control: {
|
||||
type: "ephemeral",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("ProviderTransform.variants", () => {
|
||||
const createMockModel = (overrides: Partial<any> = {}): any => ({
|
||||
id: "test/test-model",
|
||||
@@ -1408,6 +1675,32 @@ describe("ProviderTransform.variants", () => {
|
||||
})
|
||||
|
||||
describe("@ai-sdk/gateway", () => {
|
||||
test("anthropic models return anthropic thinking options", () => {
|
||||
const model = createMockModel({
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
providerID: "gateway",
|
||||
api: {
|
||||
id: "anthropic/claude-sonnet-4",
|
||||
url: "https://gateway.ai",
|
||||
npm: "@ai-sdk/gateway",
|
||||
},
|
||||
})
|
||||
const result = ProviderTransform.variants(model)
|
||||
expect(Object.keys(result)).toEqual(["high", "max"])
|
||||
expect(result.high).toEqual({
|
||||
thinking: {
|
||||
type: "enabled",
|
||||
budgetTokens: 16000,
|
||||
},
|
||||
})
|
||||
expect(result.max).toEqual({
|
||||
thinking: {
|
||||
type: "enabled",
|
||||
budgetTokens: 31999,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("returns OPENAI_EFFORTS with reasoningEffort", () => {
|
||||
const model = createMockModel({
|
||||
id: "gateway/gateway-model",
|
||||
|
||||
Reference in New Issue
Block a user