Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/web/src/features/chat/utils.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ export const getAISDKLanguageModelAndOptions = async (config: LanguageModel): Pr
? await extractLanguageModelKeyValuePairs(config.headers)
: undefined,
});

return {
model: anthropic(modelId),
providerOptions: {
anthropic: {
thinking: {
type: "enabled",
budgetTokens: env.ANTHROPIC_THINKING_BUDGET_TOKENS,
}
type: "adaptive",
},
output_config: {
effort: env.ANTHROPIC_THINKING_EFFORT ?? "medium",
},
} satisfies AnthropicProviderOptions,
Comment on lines 214 to 222
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

For the current @ai-sdk/anthropicrelease, which Anthropic models supportthinking: { type: "adaptive" }andoutput_config.effort, and what exact allowed values exist for effort?

💡 Result:

Anthropic models that support thinking: { type: "adaptive" } and output_config.effort in the current @ai-sdk/anthropic release (v3.0.68 as of 2026-04-16) are Claude Opus 4.6 (anthropic/claude-opus-4-6 or claude-opus-4-6) and Claude Sonnet 4.6 (anthropic/claude-sonnet-4-6 or claude-sonnet-4-6). These are configured via providerOptions.anthropic.thinking = { type: 'adaptive' } and providerOptions.anthropic.output_config = { effort: 'low' | 'medium' | 'high' | 'max' } (or top-level effort in some docs). Exact allowed values for effort: "low", "medium", "high" (default), "max" (Opus 4.6 only in some contexts). Claude Mythos Preview (claude-mythos-preview) has adaptive as default but may not be fully production-ready in AI SDK. Support is confirmed via Vercel AI Gateway docs showing explicit examples, AI SDK provider options mentioning effort, Anthropic docs, and recent GitHub issues/PRs in vercel/ai repo addressing adaptive thinking documentation (issue #13109 closed March 2026).

Citations:


🏁 Script executed:

cat -n packages/web/src/features/chat/utils.server.ts | sed -n '200,240p'

Repository: sourcebot-dev/sourcebot

Length of output: 2225


🏁 Script executed:

# Check the full function context to see how this is used
rg -A 30 "getAISDKLanguageModelAndOptions" packages/web/src/features/chat/utils.server.ts | head -80

Repository: sourcebot-dev/sourcebot

Length of output: 2535


🏁 Script executed:

# Check what Anthropic models are defined/used in the application
rg -i "anthropic|claude" packages/web/src/features/chat/utils.server.ts | head -30

Repository: sourcebot-dev/sourcebot

Length of output: 795


🏁 Script executed:

# Find where models are configured or defined
rg -i "model.*=.*anthropic|claude" packages/web/src --type ts --type tsx | head -30

Repository: sourcebot-dev/sourcebot

Length of output: 94


🏁 Script executed:

# Check database or config files for model definitions
fd -e json -e ts -e tsx | xargs rg -l "claude|anthropic" | grep -E "(config|model|constant)" | head -10

Repository: sourcebot-dev/sourcebot

Length of output: 138


🏁 Script executed:

# Check for any existing model lists or configurations
rg -B 2 -A 2 "claude-.*opus|claude-.*sonnet" packages/web/src --type ts --type tsx

Repository: sourcebot-dev/sourcebot

Length of output: 94


🏁 Script executed:

# Search for model definitions more broadly
rg "claude-|opus|sonnet" packages/web/src --max-count=50

Repository: sourcebot-dev/sourcebot

Length of output: 215


🏁 Script executed:

# Look for environment variables or config files related to models
find packages/web/src -type f \( -name "*.json" -o -name "*.env*" -o -name "*.config.*" \) | head -20

Repository: sourcebot-dev/sourcebot

Length of output: 49


🏁 Script executed:

# Check for any model lists or arrays
rg -A 5 -B 5 "provider.*anthropic|anthropic.*model" packages/web/src

Repository: sourcebot-dev/sourcebot

Length of output: 3590


Guard Anthropic reasoning options by model capability.

Lines 214–222 unconditionally apply thinking: { type: "adaptive" } and output_config.effort to every Anthropic model. These options are supported only on Claude Opus 4.6, Claude Sonnet 4.6, and Claude Mythos Preview. If a user configures an incompatible Anthropic model (e.g., Claude 3.5 Haiku, Claude 3 Opus), the request will fail at runtime. Also, env.ANTHROPIC_THINKING_EFFORT is not validated against allowed values ("low", "medium", "high", "max").

Suggested patch
+                const isOpus47OrSonnet46 = /(?:opus[-_.]?4(?:\.6)?|sonnet[-_.]?4(?:\.6)?|mythos)/i.test(modelId);
+                const effort = env.ANTHROPIC_THINKING_EFFORT;
+                const normalizedEffort =
+                    effort === 'low' || effort === 'medium' || effort === 'high' || effort === 'max'
+                        ? effort
+                        : 'medium';
                 return {
                     model: anthropic(modelId),
                     providerOptions: {
                         anthropic: {
-                            thinking: {
-                                type: "adaptive",
-                            },
-                            output_config: {
-                                effort: env.ANTHROPIC_THINKING_EFFORT ?? "medium",
-                            },
+                            ...(isOpus47OrSonnet46 && {
+                                thinking: { type: "adaptive" },
+                                output_config: { effort: normalizedEffort },
+                            }),
                         } satisfies AnthropicProviderOptions,
                     },
                 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/web/src/features/chat/utils.server.ts` around lines 214 - 222, The
Anthropic providerOptions currently unconditionally sets thinking and
output_config (thinking.type and output_config.effort) which will fail for
models that don't support reasoning options; update the code around
providerOptions -> anthropic to first detect the configured Anthropic model name
(the same place that builds providerOptions or the variable used to select the
model) and only attach thinking: { type: "adaptive" } and output_config when the
model is one of the supported models ("Claude Opus 4.6", "Claude Sonnet 4.6",
"Claude Mythos Preview"); additionally validate env.ANTHROPIC_THINKING_EFFORT
against the allowed values ["low","medium","high","max"], defaulting to "medium"
if invalid or unset, and ensure the shaped object still satisfies
AnthropicProviderOptions when included.

},
};
Expand Down Expand Up @@ -465,4 +466,4 @@ const extractLanguageModelKeyValuePairs = async (
}

return resolvedPairs;
};
};
Loading