How Do You Cap Output Length?
How to set an output token cap, size it from real replies, and handle a reply the cap cuts off, explained simply for your AI interview.
In short
An output cap is the most tokens a model may write in one reply, set in the request as max_tokens (Anthropic) or max_output_tokens (OpenAI's Responses API). When it is hit, the reply stops, often mid-sentence, so size the cap from real replies and check whether each one finished.
11 min readBeginnerOccasional · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
An output cap limits how many tokens a model may write in one reply. Tokens are small pieces of text, often part of a word. You set it in the request: max_tokens for Anthropic, max_output_tokens for OpenAI's Responses API. When a reply hits the cap, it stops, often mid-sentence. So I size the cap from real reply lengths, leave room for reasoning, and check whether each reply finished before I use it.
An output cap is the most tokens a model may write in one reply. I set it in the request, as max_tokens for Anthropic or max_output_tokens for OpenAI's Responses API. It is a hard limit, so when a reply reaches it, the reply stops, often in the middle of a sentence. The cap cuts the reply. Brevity has to come from the prompt.
Sizing it is an engineering choice. I take a week of real replies from our logs and set the cap a little above the normal length, so most replies finish. Then I count how many replies hit the cap each week. If that share rises, the cap is too small or the prompt has grown.
The cap also sets the worst case. With 8,000 drafts a day and a cap of 400 tokens, the drafts can write at most 3.2 million output tokens a day from one call per draft. A retry or a continuation adds to that. Reasoning models add hidden thinking that counts toward the same cap, so a small cap can leave an empty reply. I leave room for that.
In the app, I check how each reply ended before I use it. A cut reply comes back as a normal response, with no error. So the code reads the end reason, then shows the cut reply honestly or asks the model to continue. It never passes half a claim letter on as finished.
What is an output cap, in plain words?
A model writes its answer one token at a time. A token is a small piece of text, often part of a word. An output cap is the most tokens the model may write in one reply. Your code sets it in the request, before the model starts.
Think of a call-centre agent with a 90-second slot for each call. The slot is a hard limit. When the timer ends, the call ends, even mid-sentence. The cap works the same way. It stops the reply when the limit comes. Brevity has to come from the prompt.
Here is the real case. A claims team uses a model to draft replies to motor insurance claims. One unusual claim can produce a page of text, which costs money and slows the screen the agent is working in. A cap keeps every draft within a size the team chose.
Key words
- Token
- A small piece of text the model reads and writes, often part of a word.
- Output cap
- The most tokens one reply may write. Your code sets it in the request.
- Stop reason
- What the API reports when a reply ends: finished, or cut by the cap.
- Reasoning tokens
- Hidden thinking some models do before they answer. It counts toward the cap.
How does the cap work in the API?
Anthropic and OpenAI both have a setting for this. Anthropic's Messages API calls it max_tokens. OpenAI's Responses API calls it max_output_tokens. The names differ, but the idea is the same.
“max_tokens is a hard per-request cap on generated tokens”
Anthropic
“An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.”
OpenAI
How a cap ends a reply
Your code
sets the cap, for example 400 tokens
Model
writes one token at a time
How it ends
Finished
the reply ends on its own
Hit the cap
the reply stops at the limit
Your app decides
show it, or ask for the rest
- 1Your code sends the request and sets the cap.
- 2If the reply finishes first, nothing is cut.
- 3If the cap comes first, the reply stops there, often mid-sentence.
- 4Your app then shows the cut reply, or asks the model for the rest.
When the cap is reached, the reply comes back as a normal response that says it was cut, with no error. Anthropic's docs put it this way: "The response reached your max_tokens limit." OpenAI marks the same case as an incomplete response, with the reason set to max_output_tokens.
Anthropic also lets you set stop sequences, which are strings you choose. The model stops when it writes one, so a reply can end at a clean boundary such as a closing tag.
How do you pick the cap size?
Pick it from data. I use the claims team again. The numbers below are made up for this example, to show the method.
Sizing the cap from real replies
Real replies
a week of lengths from your logs
Set the cap
near the top of normal, with room
What the cap decides
Long replies cut
made-up: about 1 in 25 drafts
Cost ceiling
400 tokens x 8,000 drafts a day
- 1Start from the lengths your real replies actually reach.
- 2Replies longer than the cap get cut. Made-up sample: about 1 in 25.
- 3The cap sets the most one draft can write, so the daily total has a ceiling.
- 1
Measure real replies
Take a week of replies from your logs and measure how long they run. Do not guess the length.
- 2
Set the cap near the top
Choose a size that most replies stay under, such as the 95th percentile, plus some room. This is our own rule of thumb. No vendor sets it.
- 3
Leave room for thinking
On a reasoning model, hidden thinking uses the same cap, so give it more space.
- 4
Work out the ceiling
Multiply the cap by the replies a day. The product is the most output the feature can write in a day, counting one call per reply.
- 5
Count the cut replies
Track how many replies hit the cap each week. A rising share means the cap is too small or the prompt grew.
With the made-up numbers, a cap of 400 tokens and 8,000 drafts a day gives at most 3.2 million output tokens a day from one call per draft. A retry or a continuation adds to that. This is a ceiling, and input tokens and the price per token still shape the real bill.
What happens when the cap cuts a reply?
A cut reply is the risky case, because the cut can land anywhere. Reasoning models make it worse. When I checked in November 2026, OpenAI's guide warned about the cost first, then gave a reserve to start with:
“This might occur before any visible output tokens are produced, meaning you could incur costs for input and reasoning tokens without receiving a visible response.”
OpenAI, reasoning guide
“OpenAI recommends reserving at least 25,000 tokens for reasoning and outputs when you start experimenting with these models.”
OpenAI, reasoning guide
Anthropic's docs make the matching point: thinking tokens count toward the max_tokens limit. So a cap that looks generous for the visible answer can still run out during the thinking.
Here it is in plain Python. A claims decision must be JSON for the app to read it. We pretend the model's full reply is one line of JSON. Words stand in for tokens, which is a simplification. With a cap of 12, the JSON is cut and the parser fails. With 30, it parses.
# A claims triage reply must be JSON, or the app cannot read it. A cap that cuts it leaves nothing usable.
import json
REPLY = '{ "claim": "C-4471", "decision": "fast track", "amount": 1240, "reason": "Photos match the reported damage." }'
def run_model(reply, cap):
# Simplification: one word stands in for one token.
words = reply.split()
if len(words) > cap:
return " ".join(words[:cap]), "max_tokens"
return reply, "end_turn"
for cap in (12, 30):
text, reason = run_model(REPLY, cap)
try:
data = json.loads(text)
print("cap", cap, "ok:", data["decision"])
except json.JSONDecodeError:
print("cap", cap, "failed:", reason, "left the JSON unfinished")Output
cap 12 failed: max_tokens left the JSON unfinished cap 30 ok: fast track
Tip
Never parse a reply before you know how it ended. Then decide: retry with a bigger cap, ask the model to continue, or send the case to a person.
How would you cap the cost of a bot with 8,000 replies a day?
I start with the ceiling and the cut rate, then pick a cap for each feature. A short-reply tool and a long-report tool should not share one cap.
- Cap too high
The worst case grows
A few long replies set the daily total and the wait time for everyone.
- Cap too low
Answers get cut
Users receive half a letter, and an agent has to finish it by hand.
- Cap near the top
Known ceiling, few cuts
Most replies finish, and the daily total is a number you can budget.
Watch the cut rate in production. Log each reply's end reason, so a rising share shows on a dashboard before users complain.
What does the interviewer want to hear?
A strong answer covers
- A plain definition: a cap limits how many output tokens one reply may write.
- The names: max_tokens for Anthropic, max_output_tokens in OpenAI's Responses API.
- What happens at the cap: the reply stops and is marked as cut.
- How you size it: from real replies, with room for reasoning.
- Cost: the cap sets the most one reply can write, and the daily total follows.
- A cut reply: check the end reason, then retry, continue or escalate.
Common traps
Trap"Set a low cap and the model will write a short answer."
BetterThe cap only stops the reply at the limit. Put the length in the prompt as well.
Trap"A cap is a cost limit for the whole app."
BetterIt bounds one reply's output only. Daily cost also depends on volume, input size and reasoning.
Trap"If the API returns text, the reply is complete."
BetterA cut reply comes back as normal text. Check how it ended before you use it.
Can you spot the cut-off?
Spot the problem
A claims bot must reply in JSON for the app to read. Which setup can break it?
Quick check
A reasoning model with a cap of 500 output tokens returns an empty reply. What is the likeliest cause?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Learn it in depth
Last updated on 27 November 2026
Building a feature that must fit a fixed budget or screen?
I design and build AI features and agents with the limits they need: caps sized from real data, checked replies and cost ceilings. Book a short call and tell me what your feature has to produce.