fix: Fixes #1123 - Fix anthropic provider to work with Opus 4.7 model#1124
fix: Fixes #1123 - Fix anthropic provider to work with Opus 4.7 model#1124consi wants to merge 1 commit intosourcebot-dev:mainfrom
Conversation
WalkthroughModified the Anthropic provider configuration in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/web/src/features/chat/utils.server.ts`:
- Around line 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.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1b43b3bb-42de-499f-82d7-10fe3990a78d
📒 Files selected for processing (1)
packages/web/src/features/chat/utils.server.ts
| providerOptions: { | ||
| anthropic: { | ||
| thinking: { | ||
| type: "enabled", | ||
| budgetTokens: env.ANTHROPIC_THINKING_BUDGET_TOKENS, | ||
| } | ||
| type: "adaptive", | ||
| }, | ||
| output_config: { | ||
| effort: env.ANTHROPIC_THINKING_EFFORT ?? "medium", | ||
| }, | ||
| } satisfies AnthropicProviderOptions, |
There was a problem hiding this comment.
🧩 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:
- 1: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking
- 2: https://vercel.com/docs/ai-gateway/capabilities/reasoning/anthropic
- 3: https://docs.anthropic.com/en/docs/build-with-claude/adaptive-thinking
- 4: https://ai-sdk.dev/docs/foundations/provider-options
- 5: Anthropic documentation should include adaptive thinking. vercel/ai#13109
- 6: https://vercel.co/docs/ai-gateway/capabilities/reasoning/anthropic
🏁 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 -80Repository: 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 -30Repository: 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 -30Repository: 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 -10Repository: 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 tsxRepository: sourcebot-dev/sourcebot
Length of output: 94
🏁 Script executed:
# Search for model definitions more broadly
rg "claude-|opus|sonnet" packages/web/src --max-count=50Repository: 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 -20Repository: 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/srcRepository: 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.
This fixes issue with latest Opus 4.7 in SourceBot
Summary by CodeRabbit