Skip to main content
CodeLint.Dev AI · Dev · Finance

LLM Stream Viewer

Paste a raw streamed API response and see the message it adds up to — text, reasoning, tool calls and token usage — and where the stream went wrong.

Load a sample

Parsed in your browser. The stream you paste is never uploaded.

Server-sent events as they came off the wire, one JSON chunk per line, or a JSON array of chunks. 14 events · 1.8 KB

Result

Complete Anthropic Messages stream from claude-sonnet-5-5

Stop reason
tool_use
Contents
49 characters of text · 1 tool call
Response id
msg_01Hq7vK2mZx9TnB4cQeR8sWd

Checks 0 errors · 0 warnings · 3 passed

  • Passed:Recognised as Anthropic Messages streaming.
  • Passed:The stream is complete: it ends with message_stop.
  • Passed:1 tool call reassembled with valid JSON arguments: get_weather.

Assembled message

Text
I'll check the current weather in Lisbon for you.
Tool call get_weather toolu_01T8kPq3nLm6VxYz2AbCdEfGh
{
  "location": "Lisbon, PT",
  "unit": "celsius"
}

Token usage

Input
2,460
of which read from cache
2,048
of which written to cache
0
Output
64
Total
2,524

About $0.00556 at Claude Sonnet 5.5 list prices. Cached input is billed at a different rate, so the real charge will differ. Price a whole workload

Events content_block_delta × 6 · content_block_start × 2 · content_block_stop × 2 · message_start × 1 · ping × 1 · message_delta × 1 · …

How each API streams a response

All five send server-sent events, and no two agree on anything else. This is what a parser has to know about each.

APIFramingEnds withText arrives inTool call argumentsToken usage
Anthropic Messagesevent: and data: lines; the JSON repeats the name in typemessage_stop. No [DONE]content_block_delta with a text_deltaString fragments in input_json_delta.partial_json, per content blockInput in message_start; cumulative output in message_delta
OpenAI Chat Completionsdata: lines onlydata: [DONE]choices[0].delta.contentString fragments in delta.tool_calls[].function.arguments, matched by indexA last chunk with empty choices — only if the request set stream_options.include_usage
OpenAI Responsesevent: and data: lines, each with a sequence_numberresponse.completed, response.incomplete or response.failedresponse.output_text.deltaString fragments in response.function_call_arguments.delta, matched by output_indexresponse.usage inside the final event
Gemini generateContentdata: lines only (with ?alt=sse)No end marker; the last chunk carries a finishReasoncandidates[0].content.parts[].textNot fragmented: a whole functionCall.args object in one partusageMetadata on the chunks; the last one is final
Gemini Interactionsevent: and data: lines; the JSON repeats the name in event_typeinteraction.completed, then data: [DONE]step.delta with a text deltaWhole in the step.start of a function_call step, or in argument deltasinteraction.usage inside interaction.completed

Checked on 22 November 2026 against the Anthropic streaming guide, the OpenAI Chat Completions and Responses streaming references, and the Gemini API reference. Google's reference lists the fields of a generateContent chunk but not its framing; the framing shown is what the endpoint sends.

Streaming bugs and what causes them

The failures below produce no HTTP error. The request returns 200 and the damage is in the body.

The reply stops mid-sentence and nothing reports an error

Cause: The connection closed before the final event and the client treated end-of-connection as end-of-message. Usual culprits: a proxy or load balancer idle timeout, a serverless function time limit, or response buffering in front of the API.

Fix: Treat a stream as complete only when its end marker arrives — message_stop, [DONE], response.completed or a finishReason. Raise idle timeouts on anything between you and the API, and turn off proxy buffering (for nginx, proxy_buffering off or an X-Accel-Buffering: no response header).

Unexpected end of JSON input when parsing tool arguments

Cause: Either a fragment was parsed before the call was complete, or generation hit the output token limit in the middle of the call, so the JSON was never closed.

Fix: Join every fragment for a call and parse once, when the block or item closes. Check the stop reason first: on max_tokens, length or MAX_TOKENS the arguments are incomplete and the call must not be run.

Unexpected token d in JSON at position 0

Cause: A whole line, including its data: prefix, was passed to the JSON parser — or two events arrived in one network read and were parsed as one.

Fix: Split the body into events on blank lines, take the text after data:, and join it across lines if an event has more than one. Skip lines that begin with a colon; they are keep-alive comments.

Events are sometimes missing or come out garbled

Cause: The code assumes each network read holds exactly one whole event. Reads split events anywhere, including in the middle of a multi-byte character.

Fix: Keep a buffer. Append each read to it, take out every complete event (up to a blank line), and leave the remainder for the next read. Decode bytes with a streaming decoder.

An error object appears in the stream after HTTP 200

Cause: The status line is sent before generation starts, so a failure during generation can only be reported as an event: an error event from Anthropic (overloaded_error is the common one), response.failed or error from the Responses API.

Fix: Handle error events inside the read loop, and retry them the way you would retry a 529 or 500.

usage is null on every Chat Completions chunk

Cause: Chat Completions does not report usage in a stream unless asked.

Fix: Send "stream_options": {"include_usage": true}. Usage then arrives in one extra chunk, just before [DONE], whose choices array is empty — code that reads choices[0] on every chunk will throw on it.

The tool name is undefined on later chunks

Cause: In Chat Completions the id and function.name are sent once, in the first fragment of a call. Later fragments carry only index and more of arguments. In the Responses API the name is on response.output_item.added and not on the argument events at all.

Fix: Create the call when its first fragment arrives and match later fragments by index (Chat Completions) or output_index (Responses), never by name.

A thinking block arrives with no text

Cause: Not a fault. Claude can be asked to omit its reasoning text, and newer models do so by default; the block then carries only a signature. The Responses API likewise streams a reasoning item with no text unless a summary was requested.

Fix: Keep the block and send it back unchanged on the next turn. Do not treat empty reasoning as a failed response.

Stop reasons, side by side

The same outcome has a different name in each API, and two of them never say "the model wants a tool" at all.

What happenedAnthropicChat CompletionsResponsesGemini generateContent
Finished normallyend_turnstopstatus completedSTOP
Wants a tool runtool_usetool_callsNo signal — look for function_call itemsNo signal — STOP, with functionCall parts
Hit the output limitmax_tokenslengthincomplete, reason max_output_tokensMAX_TOKENS
Stopped by a safety systemrefusal, with stop_detailscontent_filterincomplete, reason content_filterSAFETY, RECITATION, PROHIBITED_CONTENT and others
Matched a stop sequencestop_sequencestop—STOP
Paused for a provider-run toolpause_turn———
The tool call itself was malformed———MALFORMED_FUNCTION_CALL

Because two APIs give no tool signal, decide whether to run a tool from the content of the response, not from the stop reason.

Token usage fields, and what they include

The viewer converts each provider's fields to one set of figures. The catch is in what "input" means: Anthropic reports cached tokens beside the input count, the others report them inside it.

AnthropicChat CompletionsResponsesGemini generateContent
Inputinput_tokens — excludes cached tokensprompt_tokens — includes theminput_tokens — includes thempromptTokenCount — includes them
Read from cachecache_read_input_tokensprompt_tokens_details.cached_tokensinput_tokens_details.cached_tokenscachedContentTokenCount
Written to cachecache_creation_input_tokensprompt_tokens_details.cache_write_tokensinput_tokens_details.cache_write_tokens—
Outputoutput_tokens — includes thinkingcompletion_tokens — includes reasoningoutput_tokens — includes reasoningcandidatesTokenCount — excludes thinking
Reasoningoutput_tokens_details.thinking_tokenscompletion_tokens_details.reasoning_tokensoutput_tokens_details.reasoning_tokensthoughtsTokenCount

So total input for Anthropic is the three input figures added together, and billed output for Gemini is candidatesTokenCount plus thoughtsTokenCount. Gemini's Interactions API uses total_input_tokens, total_output_tokens and total_thought_tokens, with thought tokens again counted beside the output. DeepSeek adds prompt_cache_hit_tokens and sends usage on the last content chunk rather than a separate one.

Capturing a stream

Each command saves the raw body to a file you can open here. -N stops curl buffering the output.

Anthropic Messages
curl -N https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-5-5","max_tokens":512,"stream":true,
       "messages":[{"role":"user","content":"Hello"}]}' > stream.txt
OpenAI Chat Completions
curl -N https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "content-type: application/json" \
  -d '{"model":"gpt-6.2-sol","stream":true,
       "stream_options":{"include_usage":true},
       "messages":[{"role":"user","content":"Hello"}]}' > stream.txt
OpenAI Responses
curl -N https://api.openai.com/v1/responses \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "content-type: application/json" \
  -d '{"model":"gpt-6.2-sol","stream":true,"input":"Hello"}' > stream.txt
Gemini generateContent
curl -N "https://generativelanguage.googleapis.com/v1beta/models/gemini-4-neon:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "content-type: application/json" \
  -d '{"contents":[{"parts":[{"text":"Hello"}]}]}' > stream.txt
Reading a stream without losing events
// A network read is not an event. Buffer, and cut on blank lines.
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
let buffer = '';

while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  buffer += value.replace(/\r\n/g, '\n');

  let end;
  while ((end = buffer.indexOf('\n\n')) !== -1) {
    const event = buffer.slice(0, end);
    buffer = buffer.slice(end + 2);

    const data = event
      .split('\n')
      .filter((line) => line.startsWith('data:'))   // skips ": keep-alive" comments
      .map((line) => line.slice(5).trimStart())
      .join('\n');
    if (!data || data === '[DONE]') continue;

    handle(JSON.parse(data));
  }
}
// Reaching here is the connection closing — not proof the message finished.
// Check that the end marker for your API was among the events.

What the checks cover

  • Completeness —Whether the stream reaches the end marker for its format, and whether every content block or step that was opened was also closed.
  • Errors in the body —Error events and failed responses that arrive after a 200 status, and a Gemini prompt that was blocked before any output.
  • Tool calls —That each call has a name, and that its arguments are valid JSON once the fragments are joined — with the likely reason when they are not. Calls the provider runs itself, such as web search, are labelled separately.
  • Why it stopped —A stop at the token limit, a stop by a safety system, an abnormal stop, a stop reason that says "tool" with no tool call in the stream, and the reverse.
  • The capture itself —Events that are not valid JSON, events with no start, a format chosen by hand that does not match the events, and usage figures that are absent.

About

The LLM Stream Viewer reads a streamed model response exactly as it came off the wire and puts it back together. A streaming API does not send a message; it sends dozens or hundreds of small events, and the text, the reasoning and the arguments of each tool call are spread across them in fragments. Paste the raw body — the output of curl -N, a proxy log, or the response tab of your browser's network panel — and the viewer detects which API produced it, joins the fragments, and shows the message they add up to: text, reasoning, each tool call with its parsed arguments, the stop reason and the token usage. It then reports what is wrong with the stream, which is usually why someone is looking: it was cut off before the final event, a tool call's JSON never closed, an error arrived after the 200 status, or the usage figures are missing. It understands the Anthropic Messages API, OpenAI Chat Completions and Responses, and both Gemini APIs. Everything runs in your browser; the stream is never uploaded.

How to use

  1. 1 Capture the raw response body of a streaming request — for example with curl -N — and paste it into "Raw stream", or use "Open file". The page opens on a sample so you can see a full report first.
  2. 2 Leave "Format" on automatic detection. Choose a format by hand only if the capture is too partial to recognise.
  3. 3 Read "Result" and "Checks" first: they say whether the stream finished, why it stopped, and what is broken.
  4. 4 "Assembled message" shows the text, reasoning and tool calls the events add up to. Tool arguments are parsed and pretty-printed; if they are not valid JSON they are shown as received.
  5. 5 "Token usage" normalises each provider's field names and estimates the cost. Open any row under "Events" to see that event's payload.
Is the stream I paste sent to a server?
No. The parsing runs in JavaScript in your browser and the page makes no request with your data. That matters because a captured stream contains the model's reply, tool arguments and sometimes customer data. It also means the viewer works offline once the page has loaded.
Which APIs does it understand?
Five wire formats: the Anthropic Messages API, OpenAI Chat Completions, the OpenAI Responses API, Gemini's streamGenerateContent, and Gemini's newer Interactions API. Chat Completions is also the format most "OpenAI-compatible" services speak, so streams from DeepSeek, Mistral, xAI, Groq, OpenRouter, vLLM and Ollama's /v1 endpoint parse as that format, including DeepSeek's reasoning_content field.
How do I capture a raw stream?
The simplest way is curl with the -N flag, which turns off output buffering, saved to a file. In a browser, open the network panel, select the request and copy the Response tab (the EventStream tab shows parsed events, not the raw body). From an application, log the bytes before your SDK parses them — most SDKs expose the raw response or a debug-logging setting. Section "Capturing a stream" below has a command for each provider.
Why do my tool call arguments fail to parse?
Three causes account for nearly all of it. The stream was cut off, so the JSON was never closed. The output hit the token limit in the middle of the call — the stop reason says max_tokens, length or MAX_TOKENS. Or the code parsed a fragment instead of waiting for the call to finish: argument fragments are not valid JSON on their own and must be joined first. The viewer says which of these it is.
It says the stream is cut off, but my application got a reply. Why?
Each format has a definite end: a message_stop event, a [DONE] line, a response.completed event, or a chunk carrying a finishReason. If the capture does not contain it, either the capture is partial or the connection closed early and your client treated end-of-connection as end-of-message. The second case is a real bug: a reply that looks complete may be missing its last sentences, and its tool call may be half-formed.
How is the cost worked out?
From the token usage in the stream and CodeLint's price table, at list prices, with the long-context rate applied where a model has one. Cached input is counted at the normal input rate, so when part of the prompt was read from or written to a cache the real charge differs — the page says so when that applies. If the model id is not in the price table no cost is shown.
Does it handle Amazon Bedrock or Ollama's native API?
Not directly. Bedrock wraps events in a binary event-stream encoding rather than text server-sent events, and Ollama's native /api/chat endpoint sends its own newline-delimited JSON shape. Bedrock streams decoded to JSON by an SDK, and Ollama's OpenAI-compatible /v1 endpoint, both work.

Also callable by your AI agent

This tool is available over the free CodeLint MCP server and REST API as llm_stream_assemble — no API key. Unlike this page, an API call is processed on our server.

curl -s https://codelint.dev/api/v1/tools/llm_stream_assemble \
  -H 'content-type: application/json' \
  -d '{"stream":"data: {\"object\":\"chat.completion.chunk\",\"model\":\"gpt-6.2-sol\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"Hel\"},\"finish_reason\":null}]}\n\ndata: {\"object\":\"chat.completion.chunk\",\"model\":\"gpt-6.2-sol\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"lo\"},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n\n"}'

More in AI Tools

See all ai tools.