Max tokens
Definition
A request setting that caps how many tokens a model may generate in its reply; the model can stop earlier but never goes past the cap.
In more detail
Anthropic's Messages API calls the field max_tokens. OpenAI's Chat Completions API has deprecated max_tokens in favour of max_completion_tokens, which also counts reasoning tokens. When a Claude reply hits the cap, the response has a stop_reason of max_tokens and the text is cut off where it stopped.
Set it high enough for the longest valid answer, and check the stop reason before parsing, because a truncated JSON object will not validate. It is a ceiling for cost and latency, not a way to get shorter answers: say how long you want the answer in the prompt.
Related terms
Context window
The maximum number of tokens a model can consider in one request, covering both the input you send and the output it writes.
Reasoning effort
An API setting that controls how much a reasoning model thinks before answering, trading cost and latency against accuracy.
Stop sequence
A string sent with a request that makes the model stop generating as soon as it produces that text.
Token
The unit of text a model reads and writes, often a word or part of a word; in English a token averages about four characters of text.
Read more about Max tokens
- LLM API parameters cheat sheet
Temperature, top_p, max tokens, stop, seed, logprobs, JSON output and reasoning effort, with exact names for OpenAI, Claude and Gemini, checked on the API docs.
- Cut LLM costs with prompt caching and token budgets
Lay out prompts so the provider can cache them, measure tokens before you send, and use batch processing and model routing to cut what each request costs.
- LLM cost optimisation
Cutting LLM costs with caching, model routing, batching and budgets.
- Token
The unit of text a model reads and writes, often a word or part of a word; in English a token averages about four characters of text.