> ## Documentation Index
> Fetch the complete documentation index at: https://docs.llmeasy.ru/llms.txt
> Use this file to discover all available pages before exploring further.

# What is max_tokens? What happens if I do not set it?

> Understand max_tokens, max_completion_tokens, and max_output_tokens, and how to set an output token limit for model calls.

## 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

| Concept          | Meaning                                                             |
| ---------------- | ------------------------------------------------------------------- |
| Input tokens     | Your messages, context, file content, tool results, and other input |
| Output tokens    | The visible response generated by the model                         |
| Reasoning tokens | Hidden reasoning tokens used internally by some reasoning models    |
| Context window   | The shared limit used by input, output, and some internal tokens    |
| Output limit     | The 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

| Parameter               | Common use case                                                   |
| ----------------------- | ----------------------------------------------------------------- |
| `max_tokens`            | Claude / Anthropic Messages API, and some Chat Completions setups |
| `max_completion_tokens` | Some OpenAI reasoning models through Chat Completions             |
| `max_output_tokens`     | Common 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:

| Scenario                           | Possible result                                   |
| ---------------------------------- | ------------------------------------------------- |
| Claude / Anthropic-compatible API  | May require an explicit `max_tokens` value        |
| OpenAI-compatible Chat Completions | May use the model’s default behavior              |
| OpenAI Responses API               | May use `max_output_tokens` or the tool’s default |
| Other models                       | May 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.

## Recommended ranges

| Task                                     | Suggested range                                          |
| ---------------------------------------- | -------------------------------------------------------- |
| General Q\&A                             | `1024` - `4096`                                          |
| Code explanation / small edits           | `4096` - `8192`                                          |
| Long-form writing / complex coding tasks | `8192` or higher, depending on the model limit           |
| Batch tasks                              | Use a smaller limit to avoid unexpectedly long responses |

Check the <a href={"https://www.llmeasy.ru/pricing"}>model plaza</a> 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.

## Related docs

* [Why does Claude Code use so many tokens?](/en/faq/token-cost/claude-code-token-usage)
* [How do I choose the right AI model?](/en/faq/model-calling/model-selection-guide)
* [How should I fill in the Base URL?](/en/faq/model-calling/base-url-config)
* [What are review\_model and reasoning\_effort in Codex CLI?](/en/faq/codex/review-model-reasoning-effort)
