0PricingLogin
Claude Architect · Lesson

Stop Reasons Explained

end_turn, tool_use, max_tokens and stop_sequence.

Why Stop Reasons Matter

Every time you call the Claude API, the response comes back with a stop_reason field. It tells you why the model stopped generating.

This one field drives your whole control flow. A reliable agent inspects stop_reason after each turn and decides what to do next based on it.

There are four values you must know: end_turn, tool_use, max_tokens, and stop_sequence. Let's learn each one.

Where to Find It

The stop_reason lives on the response object returned by messages.create.

Read it directly. Do not scan the text output for words like "done" or "finished" to decide what happened. The model controls stop_reason; text is just content.

from anthropic import Anthropic

client = Anthropic()
response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)

print(response.stop_reason)  # "end_turn"

All lessons in this course

  1. The Claude Model Family
  2. Anatomy of an API Request
  3. Stop Reasons Explained
  4. Tokens, Context Windows & Cost
← Back to Claude Architect