fix: variant logic for anthropic models through openai compat endpoint (#11665)

This commit is contained in:
Aiden Cline
2026-02-01 14:50:49 -06:00
committed by GitHub
parent d52ee41b3a
commit f6948d0ffa
2 changed files with 2 additions and 170 deletions

View File

@@ -395,31 +395,6 @@ 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":
@@ -719,21 +694,9 @@ export namespace ProviderTransform {
const modelCap = modelLimit || globalLimit
const standardLimit = Math.min(modelCap, globalLimit)
// 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"
) {
if (npm === "@ai-sdk/anthropic" || npm === "@ai-sdk/google-vertex/anthropic") {
const thinking = options?.["thinking"]
// 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 budgetTokens = typeof thinking?.["budgetTokens"] === "number" ? thinking["budgetTokens"] : 0
const enabled = thinking?.["type"] === "enabled"
if (enabled && budgetTokens > 0) {
// Return text tokens so that text + thinking <= model cap, preferring 32k text when possible.