fix(anthropic): thinking budget should not add to max tokens (#131)

Carlos Alexandro Becker created

Change summary

providers/anthropic/anthropic.go                                                                     | 1 
providertests/testdata/TestAnthropicThinking/claude-sonnet-4/thinking-streaming.yaml                 | 2 
providertests/testdata/TestAnthropicThinking/claude-sonnet-4/thinking.yaml                           | 2 
providertests/testdata/TestAnthropicThinkingWithCacheControl/claude-sonnet-4/thinking-streaming.yaml | 2 
providertests/testdata/TestAnthropicThinkingWithCacheControl/claude-sonnet-4/thinking.yaml           | 2 
5 files changed, 4 insertions(+), 5 deletions(-)

Detailed changes

providers/anthropic/anthropic.go 🔗

@@ -298,7 +298,6 @@ func (a languageModel) prepareParams(call fantasy.Call) (*anthropic.MessageNewPa
 				Details: "TopK is not supported when thinking is enabled",
 			})
 		}
-		params.MaxTokens = params.MaxTokens + thinkingBudget
 	}
 
 	if len(call.Tools) > 0 {

providertests/testdata/TestAnthropicThinking/claude-sonnet-4/thinking-streaming.yaml 🔗

@@ -8,7 +8,7 @@ interactions:
     proto_minor: 1
     content_length: 562
     host: ""
-    body: '{"max_tokens":8096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}],"stream":true}'
+    body: '{"max_tokens":4096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}],"stream":true}'
     headers:
       Accept:
       - application/json
@@ -103,7 +103,7 @@ interactions:
     proto_minor: 1
     content_length: 1796
     host: ""

providertests/testdata/TestAnthropicThinking/claude-sonnet-4/thinking.yaml 🔗

@@ -8,7 +8,7 @@ interactions:
     proto_minor: 1
     content_length: 548
     host: ""
-    body: '{"max_tokens":8096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}]}'
+    body: '{"max_tokens":4096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}]}'
     headers:
       Accept:
       - application/json
@@ -38,7 +38,7 @@ interactions:
     proto_minor: 1
     content_length: 1891
     host: ""

providertests/testdata/TestAnthropicThinkingWithCacheControl/claude-sonnet-4/thinking-streaming.yaml 🔗

@@ -8,7 +8,7 @@ interactions:
     proto_minor: 1
     content_length: 636
     host: ""
-    body: '{"max_tokens":8096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","cache_control":{"type":"ephemeral"},"type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","cache_control":{"type":"ephemeral"},"type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}],"stream":true}'
+    body: '{"max_tokens":4096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","cache_control":{"type":"ephemeral"},"type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","cache_control":{"type":"ephemeral"},"type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}],"stream":true}'
     headers:
       Accept:
       - application/json
@@ -106,7 +106,7 @@ interactions:
     proto_minor: 1
     content_length: 1842
     host: ""

providertests/testdata/TestAnthropicThinkingWithCacheControl/claude-sonnet-4/thinking.yaml 🔗

@@ -8,7 +8,7 @@ interactions:
     proto_minor: 1
     content_length: 622
     host: ""
-    body: '{"max_tokens":8096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","cache_control":{"type":"ephemeral"},"type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","cache_control":{"type":"ephemeral"},"type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}]}'
+    body: '{"max_tokens":4096,"messages":[{"content":[{"text":"What''s the weather in Florence, Italy?","cache_control":{"type":"ephemeral"},"type":"text"}],"role":"user"}],"model":"claude-sonnet-4-20250514","system":[{"text":"You are a helpful assistant","cache_control":{"type":"ephemeral"},"type":"text"}],"thinking":{"budget_tokens":4000,"type":"enabled"},"tool_choice":{"disable_parallel_tool_use":false,"type":"auto"},"tools":[{"input_schema":{"properties":{"location":{"description":"the city","type":"string"}},"required":["location"],"type":"object"},"name":"weather","description":"Get weather information for a location"}]}'
     headers:
       Accept:
       - application/json
@@ -38,7 +38,7 @@ interactions:
     proto_minor: 1
     content_length: 1816
     host: ""