[codex] fix anthropic thinking max_tokens floor#36
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #26 where Anthropic requests with Claude extended thinking could fail with:
Invalid request: max_tokens must be greater than thinking.budget_tokensUser impact
When users enabled
thinking_levelon Claude 4.x models without manually settingmax_tokens, rstructor sentmax_tokens=1024by default while thinking budgets can be1024/2048/4096/8192. That could produce immediate API errors forMinimal,Low,Medium, andHighthinking levels.Root cause
The Anthropic request builders hard-coded
max_tokenstoself.config.max_tokens.unwrap_or(1024)and did not enforce Anthropic's requirement thatthinking.budget_tokens < max_tokens.Anthropic docs specify this constraint in the extended thinking API docs:
https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#the-thinking-parameter
Fix
effective_max_tokens(configured_max_tokens, thinking_config)insrc/backend/anthropic.rs.max_tokens > thinking.budget_tokenswhenever thinking is enabled.materialize_internal)generate_with_metadata)max_tokensis auto-adjusted.thinking_leveldocs to state this auto-adjust behavior.Tests
Added new unit tests in
src/backend/anthropic.rscovering:Validation
cargo fmt --allcargo clippy --all-targets --all-features -- -D warningscargo test --all-featuresCloses #26.