# Why does my agent stop with stop_reason "max_tokens"?

stop_reason "max_tokens" means the model's response reached the `max_tokens` limit set in your request and was cut off before it finished. [Anthropic's docs](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons) say `stop_reason` is part of every successful Messages API response and, unlike an error, tells you why generation ended. The API returns 200, so nothing raises.

The fix is to raise `max_tokens` or ask the model to continue the response. Read the value on every response, not only when something looks wrong.

The case that hurts an agent is a cut-off tool call. When the truncated response contains an incomplete `tool_use` block, the docs say to retry the request with a higher `max_tokens` to get the full call. Running the partial call, or treating the cut-off text as the answer, sends the agent on with bad input.

A loop that never checks `stop_reason` passes a truncated reply as a finished one, and the run ends as [a silent failure](/answers/silent-failures/what-is-a-silent-failure-in-an-ai-agent).

A larger `max_tokens` fixes one run, but a response that keeps hitting the limit is worth reading in the trace.

---

Published: 2026-11-23

Sources:
- Claude API docs: Stop reasons and fallback: https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons (fetched 2026-11-23)

Source: https://tessary.ai/answers/agent-error-messages/why-does-my-agent-stop-with-stop-reason-max-tokens
More on Agent error messages: https://tessary.ai/answers/agent-error-messages
From Tessary, agent reliability for AI agents in production: https://tessary.ai
