Token streaming delivers the model's output incrementally over a long-lived connection, instead of returning the whole completion in one response.

Streaming responses (token streaming / SSE)Diagram with these labels, in reading order: Request with stream=true; Sends request; Generates token; Flushed as event; Sends token chunks; Concatenate and render; Client; Request; Server-Sent; Events Stream; Model; Generates Tokens; Token; Chunks; Concatenates; and Renders.Request with stream=trueSends requestGenerates tokenFlushed as eventSends token chunksConcatenate and renderClientRequestServer-SentEvents StreamModelGenerates TokensTokenChunksClientConcatenatesand Renders
Token Streaming Process Overview

Server-Sent Events mechanics

Server-Sent Events (SSE) is the main transport. It uses HTTP with text/event-stream and gives a one-way channel from server to client. Setting stream=true in APIs from OpenAI or Anthropic makes the model send tokens as small event chunks, each carrying the next piece (a delta) of the output.

  1. The client sends a request with stream=true.
  2. The server decodes each token and flushes it to the transport immediately.
  3. Tokens arrive as event chunks.
  4. The client concatenates the deltas and renders them in order.

Other transports fit other jobs. WebSockets suit bidirectional needs such as voice, and gRPC streaming suits service-to-service calls.

Client handling of partial output

Streaming moves complexity to the client. If the connection drops, the client must reconnect and continue without losing context. The model can also make tool calls mid-generation, so the client has to handle them and the data they return. Partial JSON must be parsed carefully, and the client needs cancellation logic.

For a long story request, the user sees the first sentences soon after the request instead of waiting for the full text. Compare tail -f on a log file: new entries appear as they are written. The difference is that tokens come from an autoregressive model, so the pace of the stream follows compute time, which varies with the output. A log line also needs no mid-stream decision, while a token stream may.

Cancel early Streaming lets a client cancel a request partway, which can save token usage and cost.

Perceived latency versus blocking requests

A blocking request leaves the user at a blank screen until the whole completion is ready, which can be several seconds or longer for long outputs. Streaming does not change total generation time. It delivers the first token as soon as the model produces it, so perceived latency falls and the user can start reading and interacting.

  • Stream for chatbots, interactive agents and long-form generation, where immediate feedback matters.
  • Do not stream for short structured extraction, or when you need the complete validated JSON before the next step. Non-streaming is simpler and avoids partial parsing.

Because total time is unchanged, streaming is a presentation choice. It does not make the model faster, and a pipeline that needs the full answer before acting gains nothing from it.

Token latency rising to 800ms

Example scenario: per-token latency grows to 800ms from an expected 200ms. These figures are illustrative.

Streaming responses (token streaming / SSE)Diagram with these labels, in reading order: Connection Stable; Connection Unstable; High Latency Detected; Check Connection Stability; Analyze Model Throughput; Inspect Server Load; Optimize Token Buffering; Reduce Response Size.Connection StableConnection UnstableHigh Latency DetectedCheck Connection StabilityAnalyze Model ThroughputInspect Server LoadOptimize Token BufferingReduce Response Size
Debugging token streaming latency

Network congestion, a proxy that buffers the stream or a server-side bottleneck can cause this. If generation is slower than expected, tokens reach the client at a slower pace.

  • Check server logs for response times and error rates.
  • Measure network latency between server and client.
  • Measure generation time per token.

Faster inference, a closer network path or more server capacity addresses the cause, and capacity adds cost. Monitor average latency per token and server load.

Back to the knowledge baseRequest an assessment