How to Tell When a Claude Reply Was Cut Off by max_tokens
A Claude reply can stop in the middle of a sentence when it runs into the max_tokens limit you set, and the API doesn't raise an error when that happens. The only sign is stop_reason. This guide sets a small limit on purpose and checks for it, with real output from Claude Opus 5.5 and anthropic 2.14.0.
Syntax
message = client.messages.create(model=<model ID>, max_tokens=<limit>, messages=[...])
if message.stop_reason == "max_tokens":
<the reply is incomplete>
Value of stop_reason | What it means |
|---|---|
end_turn | Claude finished its answer |
max_tokens | The reply reached your max_tokens limit and was cut off |
| Others | Such as tool_use when Claude wants to call a tool, or refusal when it declines |
Anthropic's stop reasons guide describes max_tokens as "The response reached your max_tokens limit." and recommends you "Raise max_tokens or continue the response".
What It Costs
The Claude API is paid: Claude Opus 5.5 costs $4 per million input tokens and $20 per million output tokens. This guide's call produced exactly 60 output tokens, $0.0012 of output.
Prerequisites
- A Claude API key, in a
.envfile asANTHROPIC_API_KEY=.... - The Anthropic Python SDK in a uv project. This guide uses anthropic 2.14.0, added with
uv add anthropic, on Python 3.15.2.
Step 1: Write the Script
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=60,
messages=[{"role": "user", "content": "Explain how a bicycle gear system works."}],
)
print("stop reason:", message.stop_reason)
print("output tokens:", message.usage.output_tokens)
if message.stop_reason == "max_tokens":
print("The reply was cut off at max_tokens.")

Explaining gears takes far more than 60 tokens, so the limit is certain to cut in.
Step 2: Run It
uv run --env-file .env cut_off.py
stop reason: max_tokens
output tokens: 60
The reply was cut off at max_tokens.

Claude used exactly the 60 tokens allowed and stopped. The call succeeded, so without this check the program would have used a half-finished answer as if it were complete.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Never checking stop_reason | Cut-off replies are used as if complete | Check it after every call |
Setting max_tokens to the length you'd like | Thinking counts against the limit too, so the answer gets even less room | Set a generous limit and ask for brevity in the prompt |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Replies end mid-sentence | stop_reason is max_tokens | Raise max_tokens |
| The reply has little or no text | Thinking used most of the limit: Anthropic's thinking documentation says thinking "counts toward max_tokens" | Raise max_tokens, or lower the effort |
FAQ
Is a cut-off reply billed?
Yes. Every token produced is billed, including those of an incomplete reply.
What should my program do when it happens?
Log it, then retry with a higher limit or tell the user the answer is incomplete. Don't silently show the partial text.
Conclusion
With max_tokens=60, Claude stopped after exactly 60 output tokens and stop_reason was max_tokens, the one sign that the reply was incomplete.
Additional Resources
- Handling stop reasons — every stop reason and what to do about it.
