Claude streams responses over server-sent events (SSE) — a simple, one-directional HTTP protocol where the server pushes small events as tokens are generated. Enable it by setting "stream": true on any Messages request. Streaming is core API surface, generally available on all five deployment surfaces: the first-party Claude API, Claude Platform on AWS, Amazon Bedrock, Vertex AI, and Microsoft Foundry. That makes this one of the most portable patterns in the catalog.
The event flow you must handle
A streamed response is a fixed choreography: message_start (a message shell with empty content), then for each content block a content_block_start, one or more content_block_delta events, and a content_block_stop; then one or more message_delta events carrying top-level changes such as the stop reason; finally message_stop. Each block carries an index matching its position in the final content array, so interleaved block types reassemble unambiguously. Two events can appear anywhere and must not break your parser: ping (keepalive) and error — an in-stream error such as overloaded_error is the streaming equivalent of an HTTP 529 and arrives after your 200 response has already begun. Any relay layer that assumes "200 means success" will silently truncate answers.
Delta events come in several types: text_delta for visible text, thinking_delta for reasoning (when displayed), signature_delta, and input_json_delta for tool-call arguments. Token counts in message_delta usage are cumulative, which is handy for live cost meters.
Architecture: a three-hop relay
The recommended shape for a production app is model → your backend → browser, not browser-direct. Your backend terminates the Claude SSE stream, applies whatever inspection or redaction you need, and re-emits events to the client over SSE or a WebSocket. SSE is usually sufficient for chat UX (one-directional, plays well with load balancers); pick WebSockets when the same connection must also carry client-to-server traffic like typing signals or cancellation. Either way, the relay is your code — the Claude side is always SSE.
from anthropic import AnthropicBedrockMantle
client = AnthropicBedrockMantle(aws_region="us-east-1")
with client.messages.stream(
model="anthropic.claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarize our Q2 policy changes."}],
) as stream:
for text in stream.text_stream:
push_to_client(text) # your SSE/WebSocket relay
print(stream.get_final_message().usage)
Partial output parsing
Text deltas can be rendered as they arrive. Tool-call arguments cannot: input_json_delta events deliver partial_json string fragments that are not valid JSON until the block completes — accumulate them and parse after content_block_stop. Current models emit one complete key/value at a time, so expect uneven pacing between events. If your UI genuinely needs to act on parameter values before the call completes (streaming a draft email a tool is composing, say), fine-grained tool streaming can be enabled per tool with eager_input_streaming. Structured outputs work with streaming too, so a schema-constrained response can still render progressively.
Failure handling in the pipeline
Three failure paths deserve explicit code. First, in-stream error events: surface them to the user and mark the message incomplete — the official SDKs retry connection errors and 429/5xx responses with exponential backoff, but a mid-stream error after output has rendered needs a UI decision, not a silent retry. Second, long requests: for anything that might exceed ten minutes of generation, streaming is not just nicer, it is the documented way to avoid timeouts (the SDKs validate that non-streaming requests won't hit the 10-minute limit). Third, thinking-enabled requests: with thinking display omitted, the thinking block opens, receives a single signature delta, and closes with no text — time-to-first-text-token improves, but your progress indicator should not assume the first event is renderable prose.
Platform notes
Streaming and fine-grained tool streaming are GA on all five surfaces. On Bedrock you have two API surfaces; this guide's examples use the current Messages surface via AnthropicBedrockMantle. Structured outputs (if you stream them) are GA everywhere except Foundry, where they are beta.
Where to go next
The streaming event reference catalogs every event type, and streaming with tools goes deeper on tool-call assembly. Start from the quickstart if you have not made a first call yet.