AI News Daily한국어
← AI tool tips
Claude Code✓ Confirmed in official docsAdded Nov 20

How to match Claude Code's output token limit to a gateway model with an environment variable

If you run Claude Code behind an LLM gateway whose model accepts fewer output tokens than Claude Code asks for, requests fail with a max_tokens error. 2.1.326 retried automatically at the limit named in the error. 2.1.329 (November 19) removed that retry and 2.1.330 (November 20) brought it back. Set the limit yourself if you are on 2.1.329 or want the first request to go through without a failure.

  1. Find the gateway model's maximum output tokens. The number in the max_tokens error message works.

  2. Put that value in the environment that starts Claude Code. 16000 below is an example.

export CLAUDE_CODE_MAX_OUTPUT_TOKENS=16000
claude

The value applies to most requests. Defaults and caps vary by model, and Claude Code lowers a value above a model's cap to the cap. For a model ID Claude Code doesn't recognize, the default is 32000 and the cap is 128000. The extended thinking budget MAX_THINKING_TOKENS is capped one token below this limit.

Get notified when a new tip lands

Tip alerts only go out in the app. Install it and turn notifications on.

Get the app

All tips →