Token streaming

Token streaming is the practice of sending a language model's output to the user piece by piece as it is generated, rather than waiting for the whole response, which is why chatbot answers appear word by word.

Language models write one token at a time, each depending on the ones before it, so a long answer can take many seconds to finish. Without streaming, an API waits until the whole answer is ready and returns it in a single response. With streaming switched on, it sends each new fragment the moment it is produced, and the application displays it as it arrives. That is why chatbot replies appear to be typed out in front of you.

Most model APIs stream over server-sent events, a web standard in which the server keeps one HTTP connection open and pushes a series of text events in one direction, using the content type text/event-stream. In Anthropic's API, setting stream to true produces a sequence that begins with a message_start event, continues with content_block_delta events that each carry a fragment of text, and ends with message_stop, with occasional ping events in between. OpenAI's Responses API sends typed events such as response.output_text.delta and response.completed.

Streaming does not make the model generate faster; the total time is the same. What changes is how long the user waits before seeing anything, a measure known as time to first token. People can start reading straight away and can stop an answer that is going wrong. Streams can carry more than text: Anthropic's API streams tool calls as chunks of partial JSON and streams the model's thinking as separate deltas.

Streaming adds complications. Errors can arrive in the middle of a response: Anthropic notes that during high demand an overloaded error may come as an event in the stream rather than as an HTTP error code. Content moderation is harder, because, as OpenAI's documentation notes, partial output is difficult to evaluate before it reaches the user, and moderation scores requested with a generation arrive only once the full output exists.

In practice, streaming is standard for chat interfaces and anything a person watches. For background and batch jobs it brings no benefit, and waiting for the complete response is simpler. Code that expects structured output such as JSON has to collect the fragments before parsing them, since a half-finished object is not valid.

Common questions

Why do chatbot answers appear word by word?

The model generates its answer one token at a time, and the service streams each token to your screen as soon as it is produced instead of waiting for the full reply. It is a real view of generation in progress, not an animation added for effect.

Does streaming make an AI model faster?

No. The model takes the same time to produce the whole answer. Streaming shortens the wait before the first words appear, which makes the service feel more responsive and lets users stop an unhelpful answer early.

What are server-sent events?

Server-sent events are a web standard for a server to push a stream of text messages to a client over a single, long-lived HTTP connection. Communication runs one way, from server to client. Most AI APIs use them to deliver streamed responses.

Can tool calls and structured output be streamed?

Yes, but they arrive in pieces. Anthropic's API, for example, streams a tool call's input as chunks of partial JSON. Application code has to collect the chunks and parse the result only once it is complete.

Finding more

Search for "LLM streaming API", "server-sent events" or "time to first token" together with the provider you use. Provider documentation is the authority on event formats and error handling, and the MDN Web Docs explain server-sent events as a web standard. Latency comparisons between services depend heavily on prompt length, model and region, so check how they were measured.

  • Streaming messagesOfficialAnthropic's description of its streaming event flow, delta types and errors mid-stream.
  • Streaming API responsesOfficialOpenAI's streaming guide, including its event types and the note on moderating partial output.
  • Using server-sent eventsReferenceMDN's explanation of the web standard most AI APIs use for streaming.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.