Token streaming

Also known as: streaming responses

On this page 7

Token streaming is the delivery of a model’s output incrementally, token by token or in small chunks, as soon as each piece is generated, rather than waiting for the complete answer. In language models, where text is produced by autoregressive next-token prediction, streaming exposes that sequential process directly to the client, so a user starts reading within a fraction of a second while the rest of the response is still being computed.

Streaming does not make generation faster overall. It changes when the user receives the output, which sharply reduces perceived latency in chat interfaces, coding assistants and voice systems. Also called streaming responses, the technique is a standard feature of model APIs and inference servers across applied artificial intelligence.

How token streaming works in a generation loop

Token streaming works by flushing each decoded token to the client inside the generation loop instead of buffering the full sequence. A decoder-only model first runs a prefill pass over the whole prompt, then enters a decode phase that emits one token per forward pass; each new token is detokenized and pushed onto an open connection.

Because tokenizers such as byte-pair encoding split text into subword units, a single token may be an incomplete character or word fragment. Servers therefore keep a small detokenization buffer and only release text once it forms valid UTF-8, which prevents broken characters in languages with multibyte scripts or in emoji sequences.

The following table lists the stages a streamed response passes through and what each stage contributes to latency.

StageWhat happensLatency effect
PrefillPrompt tokens processed in parallelSets time to first token
Decode stepOne new token sampled per forward passSets inter-token latency
DetokenizationToken IDs converted to valid textUsually negligible
TransportChunk written to the open connectionNetwork round trip and buffering
Client renderingText appended to the interfaceDepends on rendering strategy
Stages of a streamed response

Latency metrics that streaming affects

Streaming is evaluated with two separate latency metrics rather than one total response time. Time to first token (TTFT) measures the delay from request to the first visible output and is dominated by queueing and prefill, so it grows with prompt length. Inter-token latency (ITL), sometimes called time per output token, measures the gap between successive tokens during decoding.

Typical values vary widely with model size, hardware, batch load and prompt length. The ranges below describe common interactive deployments and should be read as orders of magnitude, not guarantees.

MetricTypical interactive rangeMain drivers
Time to first tokenAbout 0.2 to 2 secondsQueue depth, prompt length, prefill speed
Inter-token latencyAbout 10 to 60 millisecondsModel size, memory bandwidth, batch size
Output throughputAbout 20 to 150 tokens per second per streamDecode efficiency, speculative decoding
Total response timeSeconds to minutesOutput length times inter-token latency
Streaming latency metrics and typical ranges

Human reading speed is roughly four to eight tokens per second, so any stream faster than that feels instantaneous once it begins. This is why TTFT matters more than throughput for perceived responsiveness, while throughput matters more for long documents and batch workloads.

Transport protocols for streaming responses

Most model APIs deliver streaming responses over Server-Sent Events (SSE), a one-way HTTP mechanism in which the server sends data: lines on a long-lived connection. Each event usually carries a delta object with new text, and the stream ends with a final event that may include the finish reason and token usage counts.

Other transports suit different architectures. The table compares the common options and the situations in which each one is the sensible default.

TransportDirectionTypical use
Server-Sent EventsServer to clientPublic model APIs and web chat
WebSocketBidirectionalVoice agents and interruptible sessions
gRPC streamingServer or bidirectionalInternal microservices and inference servers
Chunked HTTPServer to clientSimple proxies and legacy clients
Common transports for token streaming

Intermediaries can silently break streaming. Reverse proxies, load balancers and compression layers that buffer responses will hold chunks until a size threshold is reached, so the client sees long pauses followed by bursts. Disabling response buffering and setting appropriate idle timeouts on every hop is a routine deployment step.

Streaming with tools, structured output and reasoning

Streaming becomes harder when output must be machine-readable rather than human-readable. A JSON object or a tool call is not valid until it is complete, so clients either wait for the closing event or use an incremental JSON parser that tolerates partial input. APIs typically stream tool arguments as separate fragments that the client must concatenate.

Reasoning models add another layer. Some APIs stream reasoning tokens or summaries before the final answer, while others hide the reasoning entirely, which lengthens the effective time to first visible token. Stop sequences and max tokens still apply, but the client learns about truncation only from the final finish reason, not from the text itself.

Benefits, limitations and common mistakes

Token streaming improves perceived responsiveness, allows users to cancel unhelpful answers early and saves compute when a client disconnects, provided the server stops generation on disconnect. It also lets downstream systems such as text-to-speech begin work before the full response exists.

The trade-off is added complexity: partial states, error handling mid-stream and moderation that must evaluate text before it is complete. The table summarizes frequent problems and their usual fixes.

SymptomLikely causeFix
Output arrives in burstsProxy or compression bufferingDisable buffering on each hop
Garbled charactersMultibyte tokens split across chunksBuffer until text is valid UTF-8
Invalid JSON in the clientParsing partial structured outputUse an incremental parser or wait
Compute wasted after cancelServer ignores client disconnectAbort generation on disconnect
Unsafe text shown brieflyModeration runs only at the endModerate chunks or delay display
Frequent streaming problems

A frequent misconception is that streaming reduces cost or total latency. Billing is based on the same number of input and output tokens, and the final token arrives at roughly the same moment as in a non-streamed call.

Put simply

A language model writes its answer one small piece at a time. Without streaming, the app waits until the whole answer is ready and then shows it at once. With streaming, each piece appears as soon as it is written.

It is like watching someone type a message instead of waiting for the finished letter. The answer does not arrive sooner in total. However, you start reading almost immediately, and you can stop the reply if it is going in the wrong direction.

In practice

A customer support team deploys an assistant that answers billing questions in a web chat. Without streaming, a typical answer of about 400 tokens at 40 tokens per second appears only after roughly ten seconds, and many users close the window or click retry, which doubles the load on the inference servers.

The engineers switch the endpoint to Server-Sent Events, disable buffering on the reverse proxy and stop generation when a browser disconnects. The first words now appear in under one second, abandoned sessions fall noticeably and retries largely disappear. Total generation time is unchanged, but the assistant feels several times faster to customers, and canceled answers no longer consume GPU time.