LLM Response Streaming: Tokens, Latency and Handling Partial Output

LLM response streaming delivers tokens as they generate, cutting time to first token. Learn how OpenAI and Claude streaming work and handle partial output.

By Galactic News Editorial · Published 2026-11-20T13:35:50+00:00 · Updated 2026-11-20T13:35:50+00:00

LLM response streaming - guide

LLM Response Streaming: Tokens, Latency and Handling Partial Output

LLM response streaming sends a model's answer token by token as it is generated, instead of waiting for the full reply. The user sees the first words in about a second, while the rest follows. This guide explains how streaming works, what it does to latency, and how to handle partial output safely in production.

How LLM response streaming works

By default, a completion request returns the whole answer at once. The model generates the full response, and only then does the server send it back. For a long answer, that wait can stretch to many seconds.

Streaming changes the delivery, not the generation. The model still produces tokens one at a time. The server sends each token to the client as soon as it exists, over a stream of server-sent events. The client prints or processes each piece on arrival.

With OpenAI's chat completions API, streaming is one flag: set stream to true when creating the completion. The response then arrives as data-only server-sent events. Chunks carry a delta field rather than a message field. Each delta holds a piece of the answer, such as a role token, a content token, or nothing when the stream ends. In the Responses API, the same idea uses typed events: response.created, response.output_text.delta, and response.completed.

Claude's Messages API works the same way. Pass stream as true, and the API returns a stream of events: message_start, content_block_start, content_block_delta, content_block_stop, message_delta, and message_stop. The text_delta events carry the incremental text. The Anthropic SDK also offers a messages.stream helper that exposes a text_stream iterator and returns the final assembled message when the stream ends.

What streaming does to latency

Streaming does not make the model faster. Total generation time stays the same. What changes is time to first token: the gap between the request and the first visible word.

OpenAI's streaming cookbook shows the difference with a simple test. A non-streamed request to count to 100 took 1.88 seconds before anything arrived. The streamed version delivered its first tokens after about 1.14 seconds, and the user watched the numbers appear as they were generated. The full reply still took roughly the same total time. The perceived wait shrank by most of a second, and the user saw progress throughout.

For chat products, that perception matters. Users read the first sentence while the rest generates. A blank screen for five seconds feels broken. A typing effect feels responsive, even when the total time is identical.

Streaming also changes server behavior. A streamed connection stays open for the whole generation. Load balancers and proxies must allow long-lived connections. Nginx, for example, can buffer a response unless buffering is disabled for the streaming route.

Handling partial output in the client

Partial output is the core challenge of streaming. The client receives fragments, and those fragments are often incomplete. A word can split across two chunks. A code block can arrive half-formed. A JSON object can cut off mid-key.

Handle this with four rules. First, accumulate the full text as chunks arrive, and render from the accumulated string rather than from each chunk alone. Second, never parse structured output until the stream finishes. A JSON parser fed a half-finished object will fail, and retrying it on every chunk wastes work. Third, treat the stream as untrusted until it completes. A connection can drop at any point, and the client must know whether it holds a complete answer or a fragment. Fourth, show a clear state while streaming: a typing indicator, a partial answer, and a final state when the stream ends.

OpenAI's SDKs make accumulation easy. In Python, iterate over the streamed response and join each chunk's delta content. In the Anthropic Python SDK, the stream helper accumulates the message for you and returns it through get_final_message. Both patterns keep the raw chunks and the assembled answer separate.

Tool calls add a wrinkle. With OpenAI, tool call arguments arrive incrementally as deltas, and the client must assemble the full JSON before invoking the tool. With Claude, tool inputs arrive as input_json_delta events with partial JSON. Never call a tool from a partial argument. Wait for the content_block_stop event, then parse once.

Streaming, tokens, and usage data

Streaming changes what the response includes. In the older chat completions flow, streamed responses did not include a usage field. The client could not see token counts from the stream itself. The Responses API and newer patterns return usage data through stream events, so check the current docs for the endpoint you use before relying on it.

Token counting still works the same way. Each token generated costs the same whether it is streamed or not. Streaming saves no tokens. It saves perceived time.

One cost to watch is abandoned streams. A user who closes a chat mid-answer leaves the server generating tokens nobody reads. Cancel the request server-side when the client disconnects. Most frameworks expose a disconnect signal for this. Ignoring it wastes compute on every abandoned conversation.

Another cost is retries. A failed stream mid-answer forces a choice: restart the whole generation, or resume from the partial text. Restarting is simpler and usually correct. Resuming saves tokens but risks a duplicated or inconsistent answer.

When not to stream

Streaming is not always the right choice. Four cases argue against it.

First, content moderation. OpenAI notes that streaming makes moderation harder, because partial completions are harder to evaluate than full ones. If a response must pass a safety check before any user sees it, generate the full answer first, check it, then display it.

Second, structured output. When the client needs a complete JSON object, a streamed partial object adds complexity for no benefit. Generate the full response, validate it, then use it.

Third, background jobs. A batch process that summarizes documents overnight gains nothing from streaming. It reads the full answer anyway.

Fourth, short answers. A two-word reply arrives in under a second either way. Streaming adds connection handling for no visible gain.

Comparing OpenAI and Claude streaming

FeatureOpenAI chat completionsOpenAI Responses APIClaude Messages API
Enable flagstream: truestream: truestream: true
TransportServer-sent eventsServer-sent eventsServer-sent events
Chunk shapedelta with content tokensTyped events, output_text.deltacontent_block_delta with text_delta
Stream endfinish_reason stop, empty deltaresponse.completed eventmessage_stop event
SDK helperIterate the response objectIterate the streammessages.stream with text_stream and get_final_message
Usage dataNot included in streamed chunksAvailable through stream eventsinput_tokens in message_start, output_tokens in message_delta
Tool callsIncremental tool call deltasTyped function call eventsinput_json_delta events, parse after block stop

Bottom line: the APIs differ in event names, not in shape. Every provider streams deltas over server-sent events, ends with a completion event, and expects the client to accumulate the text. Code written against one provider ports to another with a thin translation layer.

Building a streaming endpoint

A production streaming endpoint has five parts. Skip one and users will notice.

  1. Start the stream fast. Send the first chunk as soon as the provider returns it. Do not buffer the response on your server before forwarding it.
  2. Disable proxy buffering. Set the header that stops nginx from holding the response. Without it, the client receives nothing until the whole answer is ready, which defeats the point.
  3. Forward events, not raw bytes. Parse the provider's stream server-side and re-emit clean events to the client. This hides provider differences and lets you inject your own events.
  4. Handle disconnects. Watch for the client closing the connection. Cancel the provider request when it happens so generation stops.
  5. Log the outcome. Record whether the stream completed, errored, or was abandoned, plus the final token count. Abandoned streams are the first sign of a prompt or latency problem.

Bottom line

LLM response streaming is a delivery choice, not a speed upgrade. It cuts time to first token, keeps users engaged during long answers, and costs nothing extra in tokens. The work sits in handling partial output: accumulate before rendering, never parse structured data mid-stream, and cancel cleanly when the client leaves. Stream when a human waits for the answer. Generate the full response when moderation, structure, or a background job comes first.