[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_

View original on GitHub ↗

38 Comments

andreweskeclarke · 9 months ago

I've seen the same problem, as have many of my teammates. Often happens with ultrathink and plan mode combined.

When I used TCP dump to see the settings, I found this JSON snippet:

"max_tokens":21333,"thinking":{"budget_tokens":31999,"type":"enabled"}

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-20250929 and that the Plan Mode <system-reminder> is present.

jimutt · 9 months ago

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.

  ⎿  Error reading file
  ⎿  API Error: 400 {"error":{"message":"{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"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\"},\"request_id\":\"req_vrtx_011CTiayeKcKJKi4Bsnp7EPE\"}. Received Model
     Group=claude-sonnet-4-5-20250929\nAvailable Model Group Fallbacks=None","type":"None","param":"None","code":"400"}}
solace-rcampbell · 9 months ago

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.

KhaiHuynhVN · 9 months ago

Same problem

JasperBraun · 9 months ago

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_budget instead of thinking_budget = new_thinking_budget.

andreweskeclarke · 9 months ago

Not quite, the problem is that their code decides to reduce max_tokens by 1/3 without adjusting the thinking.budget_tokens a similar amount. If you record the tcp traffic, you'll normally see:

{..., "max_tokens":32000,"thinking":{"budget_tokens":31999,"type":"enabled"}, ...}

Then, seemingly randomly, you'll see these JSON values and a failure:

{..., "max_tokens":21333,"thinking":{"budget_tokens":31999,"type":"enabled"}, ...}
emilmahler · 9 months ago

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)?

pluo · 9 months ago

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.

frederick-wang · 9 months ago

‌‌Encountered the same issue, hope it gets fixed soon.

animeshdas2000 · 9 months ago

We are working with the typescript SDK and encountering this issue.
At code level we've specified the thinking budget in the options

    this.options = {
      maxThinkingTokens: 0,
    };

This is how it gets processed at the gateway level.

"max_tokens": 4000,
  "thinking": {
    "budget_tokens": 4000,
    "type": "enabled"
  }

We get this response:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "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"
  },
  "request_id": "req_011CTwVqxXXXXXXN9X"
}

It looks like the SDK or CC itself isn't configuring the thinking budget to zero when explicity mentioning it - also tried removing it.

HeartLinked · 9 months ago

‌‌Encountered the same issue, hope it gets fixed soon.

michal-ciechan · 9 months ago

Still an issue on 2.0.14

mateanticevic · 8 months ago

2.0.22, still seems to be an issue.

sfc-gh-mochen · 8 months ago

same here

saada · 8 months ago

Experiencing this consistently when running /context
Version: 2.0.25

mycochang · 8 months ago

additionally, even upon changing

Updated .claude/config.json with 1 addition and 1 removal
       3      "vertexProjectId": "redacted",
       4      "vertexRegion": "europe-west1",
       5      "apiModel": "claude-sonnet-4-5@20250929",
       6 -    "maxTokens": 100000
       6 +    "maxTokens": 200000
       7    }
adamrothman · 8 months ago

I can reproduce this very reliably just by running the /context command:

> /context
  ⎿  Error: 400 `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

I'm using Sonnet 4.5 in Bedrock with the 1M context window. Claude Code v2.0.28.

nitheish-mc · 8 months ago

Im using Sonnet 4.5 in Bedrock wiht 200k token context. I only encounter this issue on >/context command.

ashwin-ant collaborator · 8 months ago

Is this happening for anyone on first-party API? Or just Bedrock and Vertex?

solace-rcampbell · 8 months ago

I only see it in Bedrock. I couldn't reproduce it in vertex or direct API.

graham-perich-coinbase · 8 months ago

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

ashwin-ant collaborator · 8 months ago

We've released a fix in 2.0.30 for the /context issue.

adamrothman · 8 months ago

It does not appear to be fixed, but at least now I'm getting a different error:

> /context
  ⎿  Error: 400 Input is too long for requested model.

These are my model settings – this is with the default model (Sonnet):

"ANTHROPIC_DEFAULT_HAIKU_MODEL": "us.anthropic.claude-haiku-4-5-20251001-v1:0",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "us.anthropic.claude-opus-4-1-20250805-v1:0",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "us.anthropic.claude-sonnet-4-5-20250929-v1:0[1m]",

Notably the /context command works fine in a fresh (empty) Claude Code session. But it does not work in an existing session with lots of back-and-forth.

adamrothman · 8 months ago

Tried again after updating to v2.0.31:

> /context
  ⎿ Error: 400 messages.425.content.0.type: Expected `thinking` or `redacted_thinking`, but found `text`. When `thinking` is enabled, a final `assistant` message must start with a
    thinking block. We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at
    https://docs.claude.com/en/docs/build-with-claude/extended-thinking

Disabled thinking and tried again:

> /context
  ⎿  Error: 400 Input is too long for requested model.
graham-perich-coinbase · 8 months ago

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.

brenwhyte · 8 months ago

☝️
That ANTHROPIC_DISABLE_THINKING key is not found here, is it even valid?

graham-perich-coinbase · 8 months ago

I think that's just an AI generated issue comment with a hallucinated fake solution

JulienFox · 8 months ago

workaround is possible by editing settings.json (in my case in ~/.claude/settings.json), by setting the "alwaysThinkingEnabled" to false.

paskal · 7 months ago

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_TOKENS and MAX_MCP_OUTPUT_TOKENS to value higher than that like 32000, however that doesn't solve the issue of claude code cutting the output tokens by itself.

laizhenyoong · 7 months ago

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.

github-actions[bot] · 6 months ago

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.

emerzon · 6 months ago

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,

narengogi · 5 months ago

this still present in 2.1.17 :'

TS-Tallo · 5 months ago

Still having this issue in 2.1.19

ravisoni7 · 5 months ago

still available in ➜ ~ claude --version
2.1.21 (Claude Code)

0x25CBFC4F · 5 months ago

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.

teaguexiao · 4 months ago

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"

teaguexiao · 4 months ago

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.