What Is Streaming?
By default the Claude API generates a complete response before returning it. The user waits, sees nothing, then receives everything at once. Streaming changes this. Claude sends the response in chunks as it generates — word by word, exactly like you see responses appear in Claude.ai. The user sees text immediately and reads along as it arrives. One field enables it:Why Streaming Matters
The difference between streaming and non-streaming is felt immediately by users — especially for longer responses.
For any application displaying Claude’s responses directly to users — chat interfaces, writing tools, coding assistants — streaming is the right choice.
How Server-Sent Events Work
Streaming responses use Server-Sent Events (SSE) — a standard web protocol for pushing a stream of data from server to client over a single HTTP connection. Instead of one JSON response, you receive a sequence of events. Each event has two parts:The Complete Event Sequence
Here is the full streaming response from a real tested request — every event in order:Breaking Down Each Event
message_start
Opens the stream. Carries the message ID and initial token count.content_block_start
Signals that a content block is opening. For standard text responses there is always one content block.ping
A keepalive signal sent by Anthropic to maintain the connection. Carries no content.content_block_delta
The actual text chunks. This is the event your application cares about most.delta.text from every content_block_delta event and append it to your display. The full response is the concatenation of all these values.
content_block_stop
The content block is complete. No more deltas for this block.message_delta
Final metadata. Carries the stop reason and output token count.stop_reason here — same values as non-streaming responses. Output tokens are only known at this point.
message_stop
The stream is fully complete. Close the connection.Processing the Stream
Your implementation needs to handle four cases:Chunk Size Is Unpredictable
Claude does not stream one word at a time. Chunks vary significantly in size. From the real test above:
Never assume chunk boundaries align with words, sentences, or paragraphs. Always concatenate and render the full accumulated text.
Token Reporting Across Events
Streaming splits token reporting across two events:
You cannot calculate the full token cost of a streaming request until the
message_delta event arrives. Plan accordingly for real-time cost tracking.
Markdown in Streamed Responses
Claude returns markdown inside streamed chunks. From the real test:**bold** instead of bold if markdown is not rendered.
Streaming and Tool Use
Streaming and tool use can be combined. When Claude decides to call a tool during a streaming response, it streams the tool use decision in chunks — thecontent_block_delta events carry input_json_delta types instead of text_delta.
This is an advanced pattern used in production agent applications where real-time feedback during tool selection improves the user experience.
When to Use Streaming
Further Reading
Streaming API Reference
Interactive playground for testing streaming requests
Tool Use
Combine streaming and tool use for real-time agent applications
Tokens
How token reporting differs between streaming and standard responses
Error Handling
Handle errors that occur mid-stream