Solution skill
Build a correct streaming SSE client for the Claude Messages API
Complete solution
Shows how to fix build a correct streaming SSE client for the Claude Messages API. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Set stream true and expect SSE. Stream responses without corrupting them. If you do not need to process text as it arrives, use the SDK's stream helper that returns the complete Message object identical to a non-streaming create: less code, fewer bugs. Tool use streams the arguments as partial JSON across many inputjsondelta events.
When to use
You are seeing this: Stream responses without corrupting them. Use this skill when you run into "Build a correct streaming SSE client for the Claude Messages API".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Stream responses without corrupting them.
- Set stream true and expect SSE. The response is a stream of server-sent events. If you do not need to process text as it arrives, use the SDK's stream helper that returns the complete Message object identical to a non-streaming create: less code, fewer bugs.
- Handle events in order per content block. Track messagestart, then per block: contentblockstart, a series of contentblockdelta events, then contentblockstop. Deltas include text deltas, thinking deltas, inputjson deltas for tool use, and citations_delta for citations. Accumulate each delta type into its block; never render a delta before its block started.
- Reassemble tool calls from inputjson deltas. Tool use streams the arguments as partial JSON across many inputjsondelta events. Concatenate the partialjson strings for the block and parse only at contentblockstop. Parsing mid-stream is the classic bug.
- Accumulate citationsdelta per text block. Each citationsdelta carries one citation appended to the current text block's citations list. Only render the citation UI once the block stops.
- Detect the real end. messagedelta carries the stopreason and final usage; messagestop ends the stream. A stream that ends without messagestop was cut: treat the response as incomplete and retry or resume, do not present a truncated answer as final.
- Reconnect safely. On a dropped connection, you cannot resume a stream mid-block: start a new request. If the request is expensive, consider whether the non-streaming call plus polling fits better than a fragile long-lived stream.
Evidence
Claims verified against Anthropic's official docs (platform.claude.com) on 2026-09-26. Evidence URLs in public_references.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_UUWoKN3-qjCgWnlvsV_LVw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Build a correct streaming SSE client for the Claude Messages API <span>— Vectle</span></a>