[BUG] max_tokens must be greater than thinking.budget_tokens
Open 💬 38 comments Opened Oct 2, 2025 by solace-rcampbell
💡 Likely answer: A maintainer (ashwin-ant, collaborator)
responded on this thread — see the highlighted reply below.
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Occasionally, when I'm running prompts, I get this error message:
⎿ API Error: 400 {"error":{"message":"{\"message\":\"`max_tokens` must be greater than `thinking.budget_tokens`. Please consult our
documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking#max-tokens-and-context-window-size\"}.
Received Model Group=bedrock-claude-4-5-sonnet\nAvailable Model Group Fallbacks=None","type":"None","param":"None","code":"400"}}
Running the request a second time often resolves the problem.
What Should Happen?
I expect no errors.
Error Messages/Logs
Steps to Reproduce
I don't have a recipe for this. I've seen this maybe 4 times since upgrading to Claude v2.x. Some other people in my team have also seen this.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.2 (Claude Code)
Platform
AWS Bedrock
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
_No response_
38 Comments
I've seen the same problem, as have many of my teammates. Often happens with
ultrathinkandplan modecombined.When I used TCP dump to see the settings, I found this JSON snippet:
It seems that Claude Code is specifying an incorrect max_token value in some code paths.
edit: Confirmed from the json that the model is
claude-sonnet-4-5-20250929and that the Plan Mode<system-reminder>is present.We are noticing the same error with Claude Code 2.0 in our configuration that uses Vertex AI. It seems like it surfaces just about any time I enable thinking mode now.
This used to only happen about once per day, but it's happened to me 6 times in the past hour. This is becoming a real problem for me.
Same problem
Restarting claude code fixes it temporarily. But after a while it comes back. Based on the error message and behavior I suspect that the thinking budged is accumulated with each query over time and not reset/reassigned for each query, i.e.
thinking_budged += new_thinking_budgetinstead ofthinking_budget = new_thinking_budget.Not quite, the problem is that their code decides to reduce
max_tokensby 1/3 without adjusting thethinking.budget_tokensa similar amount. If you record the tcp traffic, you'll normally see:Then, seemingly randomly, you'll see these JSON values and a failure:
I also have this problem on Vertex AI. Do we have to cross our fingers and hope that Anthropic will fix this bug? Or is there something we can change in our configuration (e.g. environment variables)?
I have to temporarily apply
thinking_budget_tokens := min(thinking_budget_tokens, max_tokens)to the anthropic/v1/messages requests in my local anthropic proxy. Hopefully the claude-code team can fix it soon.Encountered the same issue, hope it gets fixed soon.
We are working with the typescript SDK and encountering this issue.
At code level we've specified the thinking budget in the options
This is how it gets processed at the gateway level.
We get this response:
It looks like the SDK or CC itself isn't configuring the thinking budget to zero when explicity mentioning it - also tried removing it.
Encountered the same issue, hope it gets fixed soon.
Still an issue on 2.0.14
2.0.22, still seems to be an issue.
same here
Experiencing this consistently when running
/contextVersion: 2.0.25
additionally, even upon changing
I can reproduce this very reliably just by running the
/contextcommand:I'm using Sonnet 4.5 in Bedrock with the 1M context window. Claude Code v2.0.28.
Im using Sonnet 4.5 in Bedrock wiht 200k token context. I only encounter this issue on >/context command.
Is this happening for anyone on first-party API? Or just Bedrock and Vertex?
I only see it in Bedrock. I couldn't reproduce it in vertex or direct API.
Had to pin to 1.0.128 until this gets fixed. Current frequency of the bug on 2.x versions is untenable for production automations that leverage Claude Code
We've released a fix in 2.0.30 for the
/contextissue.It does not appear to be fixed, but at least now I'm getting a different error:
These are my model settings – this is with the default model (Sonnet):
Notably the
/contextcommand works fine in a fresh (empty) Claude Code session. But it does not work in an existing session with lots of back-and-forth.Tried again after updating to v2.0.31:
Disabled thinking and tried again:
I just logged another occurrence of this issue today even on 1.0.128
This leads me to believe this bug is not related to the 2.0 upgrade, but rather a systemic issue with Vertex and Bedrock inference on Sonnet 4-5 in general.
☝️
That
ANTHROPIC_DISABLE_THINKINGkey is not found here, is it even valid?I think that's just an AI generated issue comment with a hallucinated fake solution
workaround is possible by editing settings.json (in my case in ~/.claude/settings.json), by setting the "alwaysThinkingEnabled" to false.
As per documentation, MAX_THINKING_TOKENS is the variable which seem to be higher than output tokens in that issue, and value by default when thinking is enabled seem to be
31999.Workaround is setting
CLAUDE_CODE_MAX_OUTPUT_TOKENSandMAX_MCP_OUTPUT_TOKENSto value higher than that like32000, however that doesn't solve the issue of claude code cutting the output tokens by itself.I encountered this error while running Claude Code with Haiku 4.5. After switching the model to the default Sonnet 4.5, the problem was resolved.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
I am load balancing my requests between Azure, Vertex and Bedrock.
For some reason I only have this issue with requests sent to Azure.
I can also see entries with
"thinking": {"budget_tokens": 31999, "type": "enabled"}while{"max_tokens":500,this still present in
2.1.17:'Still having this issue in 2.1.19
still available in ➜ ~ claude --version
2.1.21 (Claude Code)
I was facing the same issue. I've replaced my environment variables to FOUNDRY (I am using Foundry via LiteLLM) ones and it fixed the problem with compacting.
We have confirmed that the issue can be reproduced on Claude Agent SDK with Bedrock . This is the SDK bug, but we can fix this by making a workaround though a proxy. Using this proxy all traffic sent by SDK is treated as Anthropic API, the proxy will convert the traffic to Bedrock. We have tested several time it resolved the issue.
This proxy is built by ECS Fargate+ALB+DDB and you can deploy it using CDK.
https://github.com/xiehust/anthropic_api_converter
At last, make sure your SDK version is 0.1.47 above and using below env variable (you will have this value after the proxy is deployed)
os.environ["ANTHROPIC_BASE_URL"] = "http://anthropic-proxy-prod-alb-90xxxxx.us-west-2.elb.amazonaws.com/"
os.environ["ANTHROPIC_API_KEY"] = "sk-fd4d84f5b17xxxxxxxxxx"
We found that this is related to Claude Code using WRITE tool to generate file with long output token (>21333), it would always hit the issue.