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

AI and LLM interview question Q338, Inference, performance and cost. Beginner, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-cap-output-length

## Say it in 30 seconds

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.

## Say it in 2 minutes

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.

- **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)

*Diagram, How a cap ends a reply: Your code sets the cap, and the model writes until the reply ends or the cap is reached. The reply says which one happened. Only the cut case needs handling.*
1. Your code sends the request and sets the cap.
2. If the reply finishes first, nothing is cut.
3. If the cap comes first, the reply stops there, often mid-sentence.
4. Your 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.

*Diagram, Sizing the cap from real replies: A made-up example: a claims draft cap of 400 tokens, set from a week of real replies. Long drafts get cut, and the same cap fixes the worst case for daily output.*
1. Start from the lengths your real replies actually reach.
2. Replies longer than the cap get cut. Made-up sample: about 1 in 25.
3. The 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.

```python
# 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:

```text
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." Better: The 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." Better: It 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." Better: A 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?

A. A cap of 1024 tokens for replies that usually run about 300 tokens.
B. A cap of 40 tokens for claim decisions that usually need about 120.
C. A check of the reply's end reason before the app parses it.
D. A daily total of output tokens tracked across all drafts.

**Answer:** B. A cap far below the normal length cuts the JSON, so the parser fails. Size the cap from real replies, with room, and check how each reply ended.

**Quick check:** A reasoning model with a cap of 500 output tokens returns an empty reply. What is the likeliest cause?

A. The prompt is too short
B. Hidden reasoning used the whole cap before any visible text
C. The model is too small
D. Temperature is set too high

**Answer:** B. Reasoning tokens count toward the cap, so thinking can use it all before the visible answer starts. Leave more room in the cap.

## Can you answer these from memory?

**Flash cards**

- **What is an output cap?** The most output tokens one reply may write, set in the API request.
- **What are the field names?** max_tokens (Anthropic) and max_output_tokens (OpenAI Responses).
- **What happens at the cap?** The reply stops, often mid-sentence, and is marked as cut.
- **Does reasoning count?** Yes. Hidden thinking uses the same cap on reasoning models.
- **Does a cap make answers shorter?** Not by itself. Ask for brevity in the prompt too.
- **What bounds one reply's output?** Its cap. The reply cannot write more output tokens than that.

## Likely follow-up questions

- Q094 How do you control answer length and verbosity? https://designervenkat.online/interview/ai/how-do-you-control-answer-length-and-verbosity
- Q339 Why do output tokens cost more? https://designervenkat.online/interview/ai/why-do-output-tokens-cost-more
- Q340 How do reasoning tokens affect cost and latency? https://designervenkat.online/interview/ai/how-do-reasoning-tokens-affect-cost-and-latency
- Q315 Why stream tokens? https://designervenkat.online/interview/ai/why-stream-tokens
- Q334 How do you cut cost on a cloud-hosted LLM workload? https://designervenkat.online/interview/ai/how-do-you-cut-cost-on-a-cloud-hosted-llm-workload
- Q337 Timeouts, retries and backoff? https://designervenkat.online/interview/ai/timeouts-retries-and-backoff

## Learn it in depth

- [Tokens](https://designervenkat.online/learn/ai-engineering/tokens)
