diff --git a/providers/anthropic/anthropic.go b/providers/anthropic/anthropic.go index 7ec32d5..0f0c2b6 100644 --- a/providers/anthropic/anthropic.go +++ b/providers/anthropic/anthropic.go @@ -160,6 +160,16 @@ func (p *AnthropicProvider) buildMessageParams(req llm.ChatRequest) anthropic.Me slog.Info("anthropic adaptive thinking", "model", model, "effort", string(anthropicEffort(req.Reasoning))) + } else if anthropicRejectsDisabledThinking(model) { + // Opus 5.5 can't turn thinking off: {type:"disabled"} is a 400 + // ("use thinking.type.adaptive and output_config.effort"). + // Adaptive at low effort is the closest accepted "off". + params.Thinking = anthropic.ThinkingConfigParamUnion{ + OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{}, + } + params.OutputConfig = anthropic.OutputConfigParam{ + Effort: anthropic.OutputConfigEffortLow, + } } else if anthropicThinksByDefault(model) { // Opus 5 and Sonnet 5 think by default when the thinking // param is omitted entirely (unlike Opus 4.7/4.8, Fable 5, @@ -557,6 +567,13 @@ func anthropicThinksByDefault(model string) bool { return false } +// anthropicRejectsDisabledThinking reports whether the model returns a 400 +// for thinking {type:"disabled"}. Checked before anthropicThinksByDefault, +// whose "claude-opus-5" marker also matches Opus 5.5 IDs. +func anthropicRejectsDisabledThinking(model string) bool { + return strings.Contains(model, "claude-opus-5-5") +} + // anthropicEffort maps the unified ReasoningMode onto output_config.effort // for adaptive-thinking-only models. func anthropicEffort(mode llm.ReasoningMode) anthropic.OutputConfigEffort { diff --git a/providers/anthropic/anthropic_test.go b/providers/anthropic/anthropic_test.go index 480c845..4e62112 100644 --- a/providers/anthropic/anthropic_test.go +++ b/providers/anthropic/anthropic_test.go @@ -759,6 +759,27 @@ func TestOpus5AndSonnet5_ThinkByDefault_ReasoningOffSendsDisabled(t *testing.T) } } +// TestOpus5_5_ReasoningOffSendsAdaptiveLow guards against a 400 from Opus +// 5.5: its ID matches the "claude-opus-5" marker, so it inherited Opus 5's +// explicit {type:"disabled"} — which Opus 5.5 rejects ("thinking.type.disabled +// is not supported for this model"). The nearest accepted equivalent of +// "reasoning off" is adaptive thinking at low effort. +func TestOpus5_5_ReasoningOffSendsAdaptiveLow(t *testing.T) { + p := NewAnthropicProvider("test-key", "") + for _, model := range []string{"claude-opus-5-5", "claude-opus-5-5-global"} { + t.Run(model, func(t *testing.T) { + got := wireJSON(t, p, llm.ChatRequest{ + Model: model, + Messages: []llm.Message{{Role: "user", Content: "hi"}}, + }) + assert.NotContains(t, got, `"disabled"`, + "Opus 5.5 rejects thinking.type.disabled") + assert.Contains(t, got, `"thinking":{"type":"adaptive"}`) + assert.Contains(t, got, `"effort":"low"`) + }) + } +} + func TestLegacyThinkingModels_KeepBudgetTokens(t *testing.T) { p := NewAnthropicProvider("test-key", "") got := wireJSON(t, p, llm.ChatRequest{