Skip to content

anthropic: switch opus 4.6/4.7 token thinking budgets to adaptive#2563

Merged
dgageot merged 3 commits intodocker:mainfrom
dgageot:board/handle-opus-4-6-4-7-thinking-fcaef6d8
Apr 28, 2026
Merged

anthropic: switch opus 4.6/4.7 token thinking budgets to adaptive#2563
dgageot merged 3 commits intodocker:mainfrom
dgageot:board/handle-opus-4-6-4-7-thinking-fcaef6d8

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 28, 2026

Anthropic's API rejects thinking.type=enabled (token-based extended thinking) for Claude Opus 4.6 and 4.7. When a user configures a token-based thinking_budget for those models, the request now fails at the provider.

This change makes the Anthropic provider transparently switch a token-based budget to adaptive thinking (default high effort) on Opus 4.6 / 4.7 (including dated variants like claude-opus-4-6-20251101), with a slog.Warn so the substitution is visible. Other models keep the existing token-based path unchanged.

Behavior

  • claude-opus-4-6 / claude-opus-4-7 (and *-<date>) + thinking_budget: <tokens>thinking.type=adaptive, output_config.effort=high.
  • Same models + explicit thinking_budget: adaptive (or adaptive/<level>) → preserved as-is.
  • Same models + disabled / zero / negative budgets (thinking_budget: 0, thinking_budget: none, negative tokens) → passed through untouched, so thinking stays off. (Important: without this guard, those would have been silently flipped to adaptive thinking.)
  • Any other model → unchanged.
  • max_tokens auto-adjustment is skipped when the budget will be coerced, so an oversized token budget on Opus 4.6/4.7 no longer errors out or inflates max_tokens.

Tests

  • TestRequiresAdaptiveThinking covers prefix matching, dated variants, case/whitespace, and non-matches like claude-opus-4-60, sonnet/haiku models, etc.
  • TestCoerceAdaptiveThinking covers the coercion path, the no-op paths (already adaptive, non-affected model), and the disabled/non-positive guards.
  • TestApplyThinkingConfig and TestApplyBetaThinkingConfig gain Opus 4.6/4.7 cases verifying both SDK type families end up with OfAdaptive set, the right effort, and thinking_display preserved.
  • TestAdjustMaxTokensForThinking gains Opus 4.6/4.7 cases verifying no error / no auto-adjust.

golangci-lint run ./... → 0 issues. go test ./... → all packages pass.

dgageot added 3 commits April 28, 2026 09:45
Without this guard, opus 4.6/4.7 would silently flip thinking_budget: 0, thinking_budget: none, or negative token budgets into adaptive thinking, enabling thinking when the user disabled it.
@dgageot dgageot requested a review from a team as a code owner April 28, 2026 08:04
@dgageot dgageot merged commit 27f98ce into docker:main Apr 28, 2026
9 checks passed
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