Sub topic 7
Output limits when reasoning shares the budget
This chapter assumes you have called an LLM API from Python and know what tokens, context windows, and a maximum output setting are. It covers one narrow problem: reasoning tokens and the visible answer draw from the same output limit.
The limit counts more than the answer
With a standard chat model, the maximum output setting caps the text you see. With a reasoning model, the cap covers two things:
- The reasoning tokens the model spends thinking.
- The visible answer tokens.
The model thinks first, then answers. If thinking uses up the whole limit, no room is left for the answer.
The failure mode: an empty answer
Suppose you set a limit of 200 tokens on a hard problem. The model may spend all 200 on reasoning. You are billed for those 200 tokens and get back no visible text.
The response tells you this happened. In the OpenAI Responses API, check the status and incomplete_details fields. In the Anthropic Messages API, check stop_reason. A value of max_tokens means the limit was hit.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="o4-mini",
reasoning={"effort": "high"},
max_output_tokens=200,
input="Find all integer solutions to x^2 - 5y^2 = 1 with 0 < x < 500.",
)
if response.status == "incomplete":
print("Stopped early:", response.incomplete_details.reason)
print("answer text:", repr(response.output_text))
print("reasoning tokens:", response.usage.output_tokens_details.reasoning_tokens)
print("total output tokens:", response.usage.output_tokens)If the status is incomplete and the reason is max_output_tokens, the limit was too low for this effort level. Raise it or lower the effort.
Anthropic: the budget sits inside the limit
With Anthropic extended thinking, you set two numbers. budget_tokens is the amount the model may spend thinking. max_tokens is the total output limit. The rule is that max_tokens must be larger than budget_tokens.
The gap between them is the room left for the answer. A budget of 2000 with a limit of 2100 leaves about 100 tokens of answer, which is too little for most tasks.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=4096,
thinking={"type": "enabled", "budget_tokens": 2000},
messages=[
{"role": "user", "content": "Is 3599 a prime number? Explain briefly."}
],
)
print("stop reason:", response.stop_reason)
print("output tokens:", response.usage.output_tokens)Here the answer has up to 2096 tokens of room. The budget is a target, not a guarantee, so the model may use fewer thinking tokens than the budget allows.
Choosing a limit
A practical approach:
- Estimate the answer length you need, in tokens.
- Estimate the reasoning the task needs at your chosen effort. Measure it on a few real prompts by reading the reasoning token count.
- Add the two, then add headroom, since reasoning length varies from run to run.
| Effort | Typical reasoning | Suggested limit approach |
|---|---|---|
| Low | Short | Answer length plus a small margin |
| Medium | Moderate | Answer length plus a generous margin |
| High | Long and variable | Answer length plus a large margin, tested on hard cases |
These rows describe a pattern, not fixed numbers. Reasoning length depends on the model and the task, so measure your own.
Common mistakes
- Copying a limit from a standard model. A limit that suits a chat model can starve a reasoning model.
- Ignoring the stop reason. An empty
output_textis not an error by itself. Check why generation stopped. - Setting the limit equal to the budget. On Anthropic this is rejected, and a limit barely above the budget leaves almost no answer space.
- Forgetting the cost. Reasoning tokens that hit the limit are still billed.
Exercise
You call a reasoning model with a maximum output of 1000 tokens. The response comes back with empty text, and usage shows 1000 output tokens, 1000 of them reasoning tokens. What happened, and what are two ways to fix it?
Show answer
The model spent the entire output limit on reasoning, so no tokens were left for the answer. The response was cut off and you were billed for all 1000 tokens. To fix it, raise the maximum output limit, or lower the effort level (or thinking budget) so less of the limit goes to reasoning.