Skip to content

AI Glossary · Concepts

What is Max Tokens?

Max Tokens

Max tokens is a request setting that caps how many tokens a model may generate in one response. When the cap is reached, the output stops, even mid-sentence, and the API reports that the length limit was the reason.

Also known as: max_tokens, maximum output tokens, max output tokens, max_output_tokens, maxOutputTokens, output token limit

· Chain of Thought

AI Engineering

  • 2 explainers
  • 3 sources

If you ask for a summary with max tokens set to 100, the model can produce at most 100 tokens, roughly 75 English words. If its summary would run longer, it stops at the limit and the response is cut off. APIs flag this so code can tell a finished answer from a truncated one: Anthropic’s API returns a max_tokens stop reason and Google’s Gemini API a MAX_TOKENS finish reason (Anthropic; Gemini API). The setting goes by different names: max_tokens, max_output_tokens, maxOutputTokens, or max_new_tokens in Hugging Face.

Max tokens is a ceiling, not a target. Models usually stop on their own sooner, and asking for a high limit does not make an answer longer. To get a shorter answer, say so in the prompt; use the limit as a guardrail on cost and latency, since output tokens are typically billed and generated one at a time.

It is also different from the context window, which limits input and output together. With reasoning tokens, the hidden thinking counts against the same output budget. OpenAI warns that a reasoning model can hit the limit before writing any visible answer, while still charging for the tokens it used (OpenAI), and Anthropic says thinking tokens count toward max_tokens (Anthropic). A limit that is too low is a common cause of broken structured output, such as JSON missing its closing brackets, so always check the stop reason before parsing.

Sources

  • Anthropic: Create a Message (API reference) — Defines max_tokens as the maximum number of tokens to generate before stopping, notes models may stop earlier, and says thinking tokens count toward the max_tokens limit; checked October 24, 2026.
  • Google Gemini API: Generating content — Documents the maxOutputTokens setting and the MAX_TOKENS finish reason returned when the requested maximum is reached; checked October 24, 2026.
  • OpenAI: Reasoning models — Explains that max_output_tokens limits all generated tokens including reasoning tokens, and that a response can end incomplete before any visible output is produced; checked October 24, 2026.

Go deeper