fix(provider): use snake_case for thinking param with OpenAI-compatible APIs (#10109)

This commit is contained in:
Cesar Garcia
2026-01-30 22:32:02 -03:00
committed by GitHub
parent aef0e58ad7
commit 0c32afbc35
2 changed files with 144 additions and 2 deletions

View File

@@ -377,6 +377,31 @@ export namespace ProviderTransform {
case "@ai-sdk/deepinfra":
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/deepinfra
case "@ai-sdk/openai-compatible":
// When using openai-compatible SDK with Claude/Anthropic models,
// we must use snake_case (budget_tokens) as the SDK doesn't convert parameter names
// and the OpenAI-compatible API spec uses snake_case
if (
model.providerID === "anthropic" ||
model.api.id.includes("anthropic") ||
model.api.id.includes("claude") ||
model.id.includes("anthropic") ||
model.id.includes("claude")
) {
return {
high: {
thinking: {
type: "enabled",
budget_tokens: 16000,
},
},
max: {
thinking: {
type: "enabled",
budget_tokens: 31999,
},
},
}
}
return Object.fromEntries(WIDELY_SUPPORTED_EFFORTS.map((effort) => [effort, { reasoningEffort: effort }]))
case "@ai-sdk/azure":
@@ -656,9 +681,15 @@ export namespace ProviderTransform {
const modelCap = modelLimit || globalLimit
const standardLimit = Math.min(modelCap, globalLimit)
if (npm === "@ai-sdk/anthropic" || npm === "@ai-sdk/google-vertex/anthropic") {
// Handle thinking mode for @ai-sdk/anthropic, @ai-sdk/google-vertex/anthropic (budgetTokens)
// and @ai-sdk/openai-compatible with Claude (budget_tokens)
if (npm === "@ai-sdk/anthropic" || npm === "@ai-sdk/google-vertex/anthropic" || npm === "@ai-sdk/openai-compatible") {
const thinking = options?.["thinking"]
const budgetTokens = typeof thinking?.["budgetTokens"] === "number" ? thinking["budgetTokens"] : 0
// Support both camelCase (for @ai-sdk/anthropic) and snake_case (for openai-compatible)
const budgetTokens =
typeof thinking?.["budgetTokens"] === "number" ? thinking["budgetTokens"] :
typeof thinking?.["budget_tokens"] === "number" ? thinking["budget_tokens"] :
0
const enabled = thinking?.["type"] === "enabled"
if (enabled && budgetTokens > 0) {
// Return text tokens so that text + thinking <= model cap, preferring 32k text when possible.