Skip to main content

Short answer

max_tokens limits how many tokens the model can generate in one response. Different APIs and models use different field names, required settings, and default behavior. For stable output, set an explicit output limit for long answers, code generation, and documentation tasks. For Claude / Anthropic-compatible API calls, you usually need to send max_tokens explicitly.

Core concepts

ConceptMeaning
Input tokensYour messages, context, file content, tool results, and other input
Output tokensThe visible response generated by the model
Reasoning tokensHidden reasoning tokens used internally by some reasoning models
Context windowThe shared limit used by input, output, and some internal tokens
Output limitThe maximum visible output generated in one response
If the output limit is too small, the response may be cut off. If it is very large, the model will not always generate that many tokens, but long-output tasks may cost more.

Different parameter names

ParameterCommon use case
max_tokensClaude / Anthropic Messages API, and some Chat Completions setups
max_completion_tokensSome OpenAI reasoning models through Chat Completions
max_output_tokensCommon output limit field for OpenAI Responses API
If you use Codex CLI or another tool based on the Responses API, follow the field currently supported by that tool or provider. Do not hard-code the same parameter name for every model.

What happens if you do not set it

Behavior differs by provider and API:
ScenarioPossible result
Claude / Anthropic-compatible APIMay require an explicit max_tokens value
OpenAI-compatible Chat CompletionsMay use the model’s default behavior
OpenAI Responses APIMay use max_output_tokens or the tool’s default
Other modelsMay have their own default output limits
The same code can produce different output lengths after you switch models. To reduce surprises in production, set an explicit output limit.
TaskSuggested range
General Q&A1024 - 4096
Code explanation / small edits4096 - 8192
Long-form writing / complex coding tasks8192 or higher, depending on the model limit
Batch tasksUse a smaller limit to avoid unexpectedly long responses
Check the model plaza and upstream model docs for the actual maximum. Model output limits can change by version.

What to do when output is truncated

If the response contains finish_reason: "length", the model usually hit the output limit. Troubleshoot in this order:
  1. Increase the output limit field supported by the current API.
  2. Check whether you used the correct parameter name.
  3. Make the prompt more focused to reduce unnecessary output.
  4. Use a model with a larger output window.
  5. Split the task into multiple steps.

Common mistakes

  • Assuming a larger max_tokens value always makes the model write more.
  • Retrying after truncation without checking finish_reason.
  • Using an old field name with a reasoning model.
  • Ignoring hidden reasoning tokens when estimating context and cost.
  • Ignoring the model’s own maximum output limit.

About LLMEasy

LLMEasy records usage at the API Key and model request level. You can use the dashboard to observe token usage across models and tasks. The output limit field is still determined by the API format and model you use. When configuring it, check the model, Base URL, API format, and parameter name together.