Skip to main content

How to Tell When a Claude Reply Was Cut Off by max_tokens

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

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​

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_reasonWhat it means
end_turnClaude finished its answer
max_tokensThe reply reached your max_tokens limit and was cut off
OthersSuch 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 .env file as ANTHROPIC_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​

cut_off.py
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.")

The cut_off.py script in a macOS-style code window: a question that needs a long answer is sent with max_tokens 60, then the stop reason and output tokens are printed, with a message when the stop reason is max_tokens.

Explaining gears takes far more than 60 tokens, so the limit is certain to cut in.

Step 2: Run It​

Terminal
uv run --env-file .env cut_off.py
Output
stop reason: max_tokens
output tokens: 60
The reply was cut off at max_tokens.

The output in a terminal: stop reason max_tokens, output tokens 60, then 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​

MistakeWhat happensDo this instead
Never checking stop_reasonCut-off replies are used as if completeCheck it after every call
Setting max_tokens to the length you'd likeThinking counts against the limit too, so the answer gets even less roomSet a generous limit and ask for brevity in the prompt

Troubleshooting​

SymptomLikely causeFix
Replies end mid-sentencestop_reason is max_tokensRaise max_tokens
The reply has little or no textThinking 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​