In short.
Stop reasons and fallback is a Claude API guide for application developers, but its example loops do not handle every stopping condition together. It documents seven stop_reason values and explains message ordering, unfinished server calls, container reuse, truncation and streaming. Its practical value is showing why a successful API request can still require more work before an application presents an answer. SDK compatibility, operating costs and runtime reliability are not established, and no examples were executed.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete selected page at [https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons.md], including its notes on empty responses, incomplete tool calls, pending server tools, refusal exceptions, container reuse, streaming, HTTP errors and continuation examples. Linked pages are excluded, including detailed fallback, fallback-credit, tool-runner, MCP and SDK documentation. No examples or API requests were executed. Runtime behavior, exact SDK compatibility, operating costs and reuse rights remain unverified.
The overview
Identity
This Anthropic documentation page explains why Claude stops generating a Messages API response and how an application should respond. The original source address is [https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons.md], and its declared web address is [https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons].
It is an implementation guide with reference tables and examples, rather than a standalone application or installable library.
Assessment
The guide is useful when an application receives a successful API response but must decide whether to display it, continue generation, execute tools or handle a refusal. Its strongest material concerns message sequencing and the distinction between client tools and server tools.
Use it as a response-handling reference. The examples illustrate separate cases; they do not establish a complete, reliable application or demonstrate improved answer quality.
Users
The primary audience is developers integrating Claude through the Messages API, especially those building assistants that use tools, stream output or generate long responses. Experienced developers get detailed rules for preserving conversation state across multiple requests.
Beginners can start with the quick-reference table, but applying the examples requires understanding API requests, JSON responses and message history. The page provides cURL, ant CLI and SDK examples in Python, TypeScript, C#, Go, Java, PHP and Ruby.
Capabilities
The page covers all seven listed stop reasons: end_turn, max_tokens, stop_sequence, tool_use, pause_turn, refusal and model_context_window_exceeded. It also addresses empty completed turns, incomplete tool calls, waiting server tools, continuation limits and streaming events.
For refusals, it explains that stop_details identifies the triggering policy category and links to model fallback guidance. It identifies reasoning_extraction as an exception for which the prompt should change rather than retrying on another model. The linked fallback implementation is outside this page.
Using it
Requirements
Applying the guide requires access to the Messages API and code that can inspect response fields and retain message history. The HTTP examples use an API key, an anthropic-version header and a JSON request containing model, max_tokens and messages.
Tool workflows additionally require tool definitions and implementations for client tools. Some continuations require a returned container ID or the original mcp_servers configuration. Exact SDK versions, installation requirements and account eligibility are not specified.
Mechanism
stop_reason is a control-flow field in a successful response, separate from HTTP errors. end_turn means natural completion; stop_sequence identifies a configured stopping delimiter. max_tokens and model_context_window_exceeded mean output was cut short. tool_use requires client tool handling, while pause_turn means a server-tool loop reached its iteration limit.
A refusal can arrive with HTTP 200, so HTTP success alone does not establish that the requested answer was produced. During streaming, stop_reason is initially null in message_start and is supplied through message_delta.
Setup
Add explicit stop_reason handling after successful requests, alongside separate handling for HTTP failures. For a client tool call, preserve the response content unchanged as an assistant message, then append a user message containing the matching tool_result blocks.
For pause_turn, append the unchanged assistant content and continue with the same tools, without adding a user message. Return the container ID when supplied. A mixed server/client tool continuation also needs the same server-tool definitions, and an MCP continuation needs the same mcp_servers.
Example
The mixed-tool example contains a waiting web_search server call and a run_command client call. The follow-up preserves the original assistant content and supplies only the client call's tool_result in the next user message. The application supplies no result for the waiting server call; the API continues that work after receiving the client result.
The page explains that missing client results, changed tool definitions or extra text around the result blocks can cause 400 invalid_request_error responses. This is a documented example, not an executed demonstration.
Assessment & evidence
Limitations
Several examples need additional application logic. Tool execution functions are placeholders, and the simple manual tool loop returns whenever the stop reason is not tool_use, which includes pause_turn. The bounded pause helper returns only the final response, so earlier response content must be retained separately.
Some text examples extract only the first text block. An end_turn response can also be empty, and reaching a retry limit can leave output unfinished. Runtime compatibility, latency and reliability are not assessed; no code or API requests were executed.
Reasoning
The guide's central distinction matters because completion, interruption and request failure require different application behavior. A client tool call needs a result, a paused server turn needs continuation, and truncated output needs an incomplete-output path. Treating all three as a finished answer would lose that distinction.
The guide also explains why increasing max_tokens cannot solve every interruption: the context window is a separate limit, and an incomplete tool call requires a retry with a larger output allowance rather than execution of partial arguments.
Alternatives
For most tool integrations, the page recommends the Anthropic SDK tool runner as a simpler way to manage execution, result formatting and conversation history. Its linked documentation is [https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner]. Its implementation details and version requirements are not assessed here.
Manual handling remains the approach illustrated on this page. For the full response schema, it points to [https://platform.claude.com/docs/en/api/messages/create], whose contents are outside the selected scope.
Evidence
The evidence consists of the complete selected documentation page, including its reference table, explanatory notes and code examples. The source snapshot has SHA-256 e73bc3d6dcb8b8593f3fe4d192d2dd573ab0704df82f66fb7ad3d609acff0f4c.
This supports an account of the documented API behavior and implementation patterns. It provides no independent execution results, benchmarks or measured fallback success rates. Linked pages supply references, not additional assessed evidence.
Access & freshness
Costs
The page supplies no API token prices, tool prices or total implementation cost. Continuations and retries make additional requests, but their monetary cost is unknown from this page.
It links to fallback-credit guidance about avoiding duplicate prompt-cache charges for certain model fallbacks. The page directs developers implementing client-side retries from its listed models, except Claude Haiku 5.5, to fallback-credit guidance. Credit amounts and full conditions are not provided here, so savings cannot be calculated.
Rights
The page does not include a licence or explicit reuse and redistribution terms for its prose or code examples. Those rights are unknown from the available text.
Freshness
The source snapshot was captured on 25 November 2026. The page supplies no publication or last-updated date. Its examples use claude-opus-5-5 and the HTTP API version header 2026-10-21; these are example settings, not independent confirmation of model availability or SDK compatibility.
The page says model_context_window_exceeded is available on Claude 4.5 and later models, while earlier models require the model-context-window-exceeded-2025-08-26 beta header. Compatibility with a particular deployment remains unverified.
Actions
Use the seven stop reasons to define explicit response-handling branches. Include empty end_turn responses, truncated tool arguments, mixed client/server calls, repeated pauses and refusals. Preserve all content needed for the conversation and give continuation loops a request limit.
Before deployment, verify the chosen SDK and model support, message ordering, container reuse and final streaming stop reason. Decide how the application presents output when continuation limits are exhausted. Pricing and reuse terms need separate confirmation.
