Streaming chunk reassembler
When you call an LLM with stream: true, the response arrives as a sequence of
tiny Server-Sent Events — each carrying one or two tokens inside a JSON delta.
Reading that raw stream by hand is miserable. This tool takes the raw SSE body,
parses every data: line, pulls the incremental token out of each chunk, and
stitches them back into the single, complete response the model produced.
Why you would use this
Streaming is invisible when everything works: the client library reassembles chunks and you see finished text. It becomes very visible when something goes wrong:
- Debugging a truncated response — the model’s output cut off mid-sentence
and you want to inspect the raw chunks to see whether the
[DONE]sentinel arrived or the stream just stopped. - Writing a custom streaming client — you want to verify your parser is assembling deltas correctly before shipping.
- Reading curl output — you ran a quick
curltest with--no-bufferand need the readable text back from the raw SSE lines. - Auditing a logged stream — your middleware wrote raw events to disk and you want the plain reassembled text.
How it works
The parser scans the input line by line. For each line beginning with data:,
it strips the prefix, skips the [DONE] sentinel, and attempts to JSON-parse the
payload. It then extracts the incremental content from the common streaming
shapes — OpenAI’s choices[0].delta.content, Anthropic’s delta.text, and a
few fallbacks — and appends it to a growing buffer. Lines that are plain text
rather than JSON are appended directly. The result is the full reassembled
string, along with a count of how many chunks contributed and a pretty-printed
view if the output is valid JSON.
What the raw stream looks like
A typical OpenAI chat-completion stream (abbreviated) looks like this:
data: {"choices":[{"delta":{"role":"assistant"}}]}
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":", world"}}]}
data: {"choices":[{"delta":{"content":"!"}}]}
data: [DONE]
Pasting that block gives the reassembled text Hello, world! and reports that
3 chunks contributed (the role-only first chunk carries no content text). The
Anthropic format uses delta.text inside content_block_delta events; the
tool detects both automatically.
How to capture the raw stream
- Chrome DevTools: Open the Network tab, find the fetch or XHR request,
and view the Response tab. For streaming requests you may need to use
EventSourcein the Console to capture events as they arrive. - curl: Use
curl ... -Nor--no-bufferand redirect to a file. The rawdata:framing is preserved exactly. - Proxy or middleware logs: Write the raw
res.bodybefore any transformation and you will have the exact stream bytes.
Tips and notes
- Grab the raw body, not the parsed view. The
data:prefix framing must be intact. - Blank lines are fine. SSE separates events with blank lines; the parser ignores them.
- Mixed event types. If a stream interleaves event types (for example
Anthropic’s
content_block_deltaandmessage_delta), only text-bearing deltas are concatenated. - JSON output. If the model streamed structured JSON (for example a tool-use block), the reassembled string is the raw JSON and the tool tries to pretty-print it.
- Everything is local. No network calls are made, so sensitive transcripts stay on your machine.