Sub topic 7
Output limits when reasoning shares the budget
What this chapter assumes
You should already know what a token is, what a context window is, and what a maximum output token setting does in a standard chat call. You should also have read the earlier chapters on reasoning tokens and on effort levels and thinking budgets. This chapter covers one consequence of that design: the output limit you set covers the hidden reasoning as well as the visible answer.
The shared budget
In a standard chat model, the output limit caps the text you see. If you set it to 500 tokens, the answer is at most 500 tokens.
In a reasoning model, the model first produces reasoning tokens and then the final answer. Both count as output tokens. The output limit applies to the total.
output limit >= reasoning tokens + visible answer tokensIf reasoning uses most of the limit, little room remains for the answer. If reasoning uses all of it, the answer is empty or cut off, and you still pay for every token generated.
Providers name the parameter differently:
| Provider API | Parameter | What it caps |
|---|---|---|
| OpenAI Responses API | `max_output_tokens` | Reasoning tokens plus visible output |
| Anthropic Messages API | `max_tokens` | Thinking tokens plus visible text |
Parameter names and exact rules change between API versions, so check the current documentation for your model.
What truncation looks like
When a standard model hits the limit, you get a partial answer. When a reasoning model hits it, there are two cases.
- The limit is reached during the answer. You get a partial answer, as before.
- The limit is reached during reasoning. The visible answer is empty. The response reports that it is incomplete, and the usage data shows that nearly all output tokens went to reasoning.
The second case is the one that surprises people. The request succeeds at the HTTP level, you are billed, and output_text is an empty string. A check such as if response.output_text: hides the cause unless you also inspect the status.
Detecting it with OpenAI
The Responses API reports a status of "incomplete" and an incomplete_details object with a reason such as max_output_tokens.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="o4-mini",
reasoning={"effort": "high"},
max_output_tokens=300,
input="Find all integer solutions to x^2 - 5y^2 = 1 with 0 < x < 1000.",
)
details = response.usage.output_tokens_details
print("status:", response.status)
print("reasoning tokens:", details.reasoning_tokens)
print("total output tokens:", response.usage.output_tokens)
if response.status == "incomplete":
reason = response.incomplete_details.reason
print("incomplete because:", reason)
if details.reasoning_tokens >= response.usage.output_tokens * 0.9:
print("Reasoning consumed almost the whole budget.")
else:
print(response.output_text)With a limit this low and high effort, the incomplete branch is likely. Raise max_output_tokens and the same request finishes.
Detecting it with Anthropic
The Messages API reports a stop_reason. A value of "max_tokens" means generation stopped at the limit. The response may contain a thinking block and a truncated or missing text block.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1500,
thinking={"type": "enabled", "budget_tokens": 1024},
messages=[
{"role": "user", "content": "Plan a three-step migration from SQLite to Postgres."}
],
)
print("stop_reason:", response.stop_reason)
print("output tokens:", response.usage.output_tokens)
text_blocks = [b.text for b in response.content if b.type == "text"]
if response.stop_reason == "max_tokens":
print("Truncated. Visible text blocks:", len(text_blocks))
print("\n".join(text_blocks))Sizing the limit
The limit has to be large enough for the reasoning you allow plus the answer you expect. Treat it as a sum of two estimates.
output limit = reasoning allowance + answer length + safety marginAnthropic: the budget sits inside the limit
With extended thinking, you set two numbers. budget_tokens is the amount the model may spend thinking. max_tokens is the overall cap. The thinking budget must be smaller than max_tokens, and the difference is the space left for the answer.
For example, with budget_tokens=2000 and max_tokens=4096, roughly 2,096 tokens remain for the visible text. If you expect a 1,500-token answer, that fits. If you expect 3,000 tokens, it does not, and you should raise max_tokens.
The budget is a target, not a strict guarantee. The model may use less, and for some models and settings the actual thinking can differ from the number you set. Leave margin.
OpenAI: effort has no fixed size
OpenAI's effort setting does not give a token number. You choose low, medium or high, and the model decides how much to reason. That means you cannot compute the reasoning share in advance. Two approaches work.
- Set a generous
max_output_tokensand let the effort level control the typical spend. - Measure
reasoning_tokenson a sample of your real prompts and set the limit above a high percentile of the totals.
OpenAI's guidance for reasoning models is to reserve a large allowance for reasoning and the answer, and to adjust from observed usage. The right number depends on your prompts.
A worked sizing example
Suppose you run a code-review assistant. Each response should be a short summary of about 400 tokens. You measure 200 sample requests at medium effort and record total output tokens.
| Percentile | Reasoning tokens | Answer tokens | Total |
|---|---|---|---|
| Median | 1,800 | 380 | 2,180 |
| 95th | 5,200 | 450 | 5,650 |
| Maximum | 11,000 | 520 | 11,520 |
A limit of 3,000 would cut off about half of the responses. A limit of 6,000 covers 95 percent. A limit of 12,000 covers all measured cases and leaves a small margin. Pick based on how costly a truncated response is for you. If a retry is cheap, 6,000 plus retry logic may be enough. If a failure reaches a user, choose the higher limit.
A higher limit costs nothing by itself. You pay for tokens generated, not for the limit. The limit only matters when a request would otherwise have used more. Do not confuse it with the thinking budget or effort, which influence how much is generated.
Interaction with the context window
The output limit is separate from the context window, but they share one constraint. The input tokens, reasoning tokens and answer tokens together must fit in the model's context window. A long prompt leaves less room for reasoning.
input tokens + reasoning tokens + answer tokens <= context windowTwo practical consequences follow.
- A very long input with a large output limit can fail the request up front, because the sum exceeds the window.
- In multi-turn conversations, how earlier reasoning is treated differs by provider. Some APIs drop earlier reasoning from the context on later turns, and others require you to pass certain reasoning items back during tool use. Check how your provider handles this, because it changes how much window each turn consumes.
Handling truncation in code
A defensive wrapper checks for truncation and retries once with a larger limit. This version is provider-neutral. You supply a function that makes the call and reports whether the response was truncated.
def call_with_headroom(call, prompt, start_limit=4000, max_limit=16000, factor=2):
"""call(prompt, limit) -> (text, truncated: bool).
Retries with a larger output limit if the response was cut off.
"""
limit = start_limit
while True:
text, truncated = call(prompt, limit)
if not truncated and text.strip():
return text, limit
if limit >= max_limit:
raise RuntimeError(
f"Still truncated at limit {limit}. Lower effort or shorten the task."
)
limit = min(limit * factor, max_limit)Retries cost money, since the first attempt is billed in full. Log how often they happen. If retries are common, raise the starting limit or lower the effort, instead of relying on the retry.
Common mistakes
- Reusing a limit from a standard model. A 500-token limit that suited a chat model leaves almost nothing for reasoning.
- Checking only for empty text. An empty answer can come from truncation, from a refusal, or from a tool call. Check the status or stop reason.
- Setting the thinking budget equal to or above
max_tokens. On Anthropic's API this is rejected or leaves no room for the answer. - Ignoring streaming. In a stream, you may see no text for a long time while reasoning runs. A timeout tuned for a standard model can fire before the first answer token. Set timeouts using measured time to first visible token.
- Assuming a bigger limit means more reasoning. The limit sets a ceiling. Effort and budget set the target.
Exercises
Exercise
You call a reasoning model with a maximum output of 800 tokens and high effort. The response succeeds, but the visible answer is empty, and usage shows 800 output tokens. What happened, and what are two ways to fix it?
Show answer
The reasoning consumed the whole 800-token limit, so the model never started the visible answer. You were billed for the 800 tokens. Fix it by raising the output limit, or by lowering the effort level (or thinking budget) so less of the limit goes to reasoning. Also check the status or stop reason in code so the failure is detected instead of returning an empty string.
Exercise
An Anthropic request uses maxtokens=3000 and budgettokens=2500. You expect a 1,200-token answer. Is this configuration safe? What would you change?
Show answer
It is not safe. Only about 500 tokens remain for the answer if the model uses the full budget, which is less than the 1,200 expected. Raise maxtokens to at least about 4,000 (2,500 + 1,200 plus margin), or lower budgettokens to about 1,500.
Exercise
Your measurements show a 95th percentile total of 5,650 output tokens and a maximum of 11,520. Does setting the limit to 12,000 make every request cost more than a limit of 6,000?
Show answer
No. You pay for tokens generated, not for the limit. A request that would have used 2,000 tokens costs the same under either limit. Only the rare requests that need more than 6,000 tokens cost more, and under the lower limit those would have been truncated.