# How do I assemble a Claude Messages SSE stream into a complete response?

Exam: CCDV-F — Claude Certified Developer - Foundations
Knowledge domain: Applications and Integration
Updated: 2026-11-25T08:29:57.831953+00:00
HTML: https://learningpathx.com/faq/CCDV-F/ccdvf-claude-sse-stream-message-lifecycle.html

## Also asked as

- Which Claude SSE events should I process to know that a streaming message is complete?
- How do I assemble Claude text and tool JSON deltas without corrupting content blocks?

Parse each Server-Sent Events (SSE) envelope and its JSON data, then advance message and block state in wire order. Consider the stream complete after a valid `message_stop` with the required blocks closed and no stream failure. The completed Message still needs stop-reason handling and application validation.

1. `message_start` initializes the Message and its metadata. The content is empty and the stop reason can be null at this point.
2. `content_block_start` opens a block at an index. Apply compatible `content_block_delta` events only to that open block. Some blocks arrive whole. Close each one on `content_block_stop`.
3. Apply `message_delta` to top-level fields such as stop metadata. Usage values there are cumulative, so update the corresponding counters instead of adding them across events.
4. On `message_stop`, return the ordered assembled result. If the connection ends first or an error arrives, mark the attempt incomplete.

Text deltas append text within one block. A tool block's `input_json_delta` contains a JSON fragment. If fragments arrive, join and parse them when the block closes, or use the SDK accumulator. For a block that arrives complete, use its supplied typed data. Keep any tool action behind the application validation and authorization boundary. Handle pings and new ignorable event types without changing assembly state. Surface invalid transitions, unsupported required block data, and SSE errors explicitly. An error can arrive after HTTP 200, and a supported SDK can surface that error through the stream reader.

**Official references**

* [Streaming Claude Messages](https://platform.claude.com/docs/en/build-with-claude/streaming)
* [Claude API error and retry reference](https://platform.claude.com/docs/en/api/errors)
* [Claude API versions](https://platform.claude.com/docs/en/api/versioning)

Source: [Reliable Claude API Streaming, Asynchronous Work, and Error Handling](https://learningpathx.com/news/reliable-claude-api-streaming-asynchronous-work-and-error-handling.html)
