stop_reason
A top-level field in Anthropic Messages API responses that indicates why the model stopped generating. It has seven possible values: end_turn, tool_use, max_tokens, stop_sequence, refusal, pause_turn, and model_context_window_exceeded.
Timeline (last 90 days)
For Agent applications using Anthropic server-side tools, after the return, you should explicitly check whether response_metadata["stop_reason"] is pause_turn, and implement retry logic yourself or log it.
After LangChain wrapping, the stop_reason of an Anthropic response can usually be read via the message's response_metadata["stop_reason"].
The Anthropic Messages API may return a response with stop_reason 'pause_turn' when server-side tools run for a long time, and the client should send that response back as-is to continue executing the unfinished tool calls.
When the model decides to use a tool, the stop_reason in the Claude API response changes to tool_use, and a tool_use block containing the tool ID, name, and input parameters appears.
The main loop translates stop_reason into the next action decision: tool_use enters the tool execution branch, max_tokens triggers max_output_tokens_escalate or max_output_tokens_recovery, and prompt_too_long maps to reactive_compact_retry.
In practice, stop_reason === 'tool_use' does not reliably reflect message structure: a response may contain a real tool call block yet report end_turn.
In streaming (SSE) mode, stop_reason is given in the message_delta event, immediately before message_stop, rather than arriving with the first event.
The stop_reason field in the top-level response of the Anthropic Messages API has seven possible values in total: end_turn, tool_use, max_tokens, stop_sequence, refusal, pause_turn, and model_context_window_exceeded.
The LangChain September update enhanced SDK run tracing capabilities, adding capture of stop_reason values for Claude SDK runs.
All Facts (10)
The stop_reason field in the top-level response of the Anthropic Messages API has seven possible values in total: end_turn, tool_use, max_tokens, stop_sequence, refusal, pause_turn, and model_context_window_exceeded.
60%UnverifiedFor Agent applications using Anthropic server-side tools, after the return, you should explicitly check whether response_metadata["stop_reason"] is pause_turn, and implement retry logic yourself or log it.
50%UnverifiedAfter LangChain wrapping, the stop_reason of an Anthropic response can usually be read via the message's response_metadata["stop_reason"].
50%UnverifiedThe Anthropic Messages API may return a response with stop_reason 'pause_turn' when server-side tools run for a long time, and the client should send that response back as-is to continue executing the unfinished tool calls.
50%UnverifiedWhen the model decides to use a tool, the stop_reason in the Claude API response changes to tool_use, and a tool_use block containing the tool ID, name, and input parameters appears.
50%UnverifiedThe main loop translates stop_reason into the next action decision: tool_use enters the tool execution branch, max_tokens triggers max_output_tokens_escalate or max_output_tokens_recovery, and prompt_too_long maps to reactive_compact_retry.
50%UnverifiedIn practice, stop_reason === 'tool_use' does not reliably reflect message structure: a response may contain a real tool call block yet report end_turn.
50%UnverifiedIn streaming (SSE) mode, stop_reason is given in the message_delta event, immediately before message_stop, rather than arriving with the first event.
50%UnverifiedThe LangChain September update enhanced SDK run tracing capabilities, adding capture of stop_reason values for Claude SDK runs.
50%UnverifiedThe two signals that drive the Agent Loop come from the stop_reason field returned by the model: when stop_reason equals tool_use, the host executes the tool and continues the loop; otherwise, the loop exits.
50%