[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3

SSE Streaming Protocol

📨 Messages API Core20 min150 BASE XP⌨ HANDS-ON LAB

The Streaming Lifecycle

When stream: true is enabled, the API responds with a series of Server-Sent Events (SSE). Understanding the lifecycle is critical for building responsive UIs. The sequence always follows this deterministic path:

  1. message_start: Provides the message ID and initial usage (input tokens).
  2. content_block_start: Indicates the start of a text or tool block.
  3. content_block_delta: Fires repeatedly with small chunks of text.
  4. content_block_stop: Signals the end of that specific content block.
  5. message_delta: Contains final metadata and stop reasons.
  6. message_stop: The final event in the stream.
// Example text delta event
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello world"}}
⌨ HANDS-ON LABStream a Response Over SSE
⭐ +150 XP

Watch the token stream live. Fire a streaming Messages API request with curl, then isolate the SSE event sequence to prove the lifecycle order.

1Send a streaming request: add "stream": true to the JSON body and use curl -N so output isn't buffered.
2Re-run the stream but pipe it through grep to print only the event: lines — the lifecycle order should match the docs.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 2 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 3
Which SSE event continuously fires as Claude generates text tokens?
message_ping
content_block_delta
stream_output
text_generate
SSE Streaming Protocol Tutorial | Messages API Core — Claude Academy