Skip to content

fix: Fixes #1123 - Fix anthropic provider to work with Opus 4.7 model#1124

Closed
consi wants to merge 1 commit intosourcebot-dev:mainfrom
consi:main
Closed

fix: Fixes #1123 - Fix anthropic provider to work with Opus 4.7 model#1124
consi wants to merge 1 commit intosourcebot-dev:mainfrom
consi:main

Conversation

@consi
Copy link
Copy Markdown

@consi consi commented Apr 16, 2026

This fixes issue with latest Opus 4.7 in SourceBot

Summary by CodeRabbit

  • Chores
    • Enhanced Anthropic AI provider configuration to enable adaptive thinking mode with configurable effort levels, replacing the previous fixed-budget token approach. This optimization allows for more flexible and contextually appropriate AI reasoning, delivering improved performance and enhanced quality across AI-assisted features.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Walkthrough

Modified the Anthropic provider configuration in getAISDKLanguageModelAndOptions by changing the thinking mode from enabled with budgetTokens to adaptive, and introduced an output_config parameter with an effort level. Cleaned up whitespace at end-of-file.

Changes

Cohort / File(s) Summary
Anthropic Provider Configuration
packages/web/src/features/chat/utils.server.ts
Updated thinking configuration from { type: "enabled", budgetTokens: ... } to { type: "adaptive" }, and added output_config: { effort: ... } parameter with environment variable fallback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main change: updating the Anthropic provider configuration to support the Opus 4.7 model by switching from enabled thinking with budget tokens to adaptive thinking with effort configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@consi consi changed the title Fixes #1123 - Fix anthropic provider to work with Opus 4.7 model fix: Fixes #1123 - Fix anthropic provider to work with Opus 4.7 model Apr 16, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed05fc4 and 5b3d551.

📒 Files selected for processing (1)
  • packages/web/src/features/chat/utils.server.ts

Comment on lines 214 to 222
providerOptions: {
anthropic: {
thinking: {
type: "enabled",
budgetTokens: env.ANTHROPIC_THINKING_BUDGET_TOKENS,
}
type: "adaptive",
},
output_config: {
effort: env.ANTHROPIC_THINKING_EFFORT ?? "medium",
},
} satisfies AnthropicProviderOptions,
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants