Glossary
Streaming responses
Streaming is a way of delivering a language model's output piece by piece as it is generated, instead of returning the whole response once it is finished.
Streaming is a way of delivering a language model’s output piece by piece as it is generated, instead of waiting for the whole response and returning it at the end. The client opens one request, and the server sends a series of small events, each carrying the next few tokens, until the answer is complete. Users see text appear within a second or so of asking, and can read it as it arrives. Most chat products stream for that reason, and most model APIs support it through a single flag on the request.
Streaming changes when output arrives and leaves the time needed to produce it much the same. A model generates its answer one token at a time in either mode. Without streaming, the server holds the tokens until the last one is ready. With streaming, it forwards them as they come. Total generation time is about the same, but the wait the user notices shrinks from the full response time to the time to first token.
How streaming works
Most hosted model APIs stream over server-sent events (SSE), a simple standard for sending a sequence of messages down one HTTP response. The client sends an ordinary request with streaming switched on. The server replies with a content type of text/event-stream and keeps the connection open, writing one event per chunk. Each event is a line of JSON describing what changed since the last one: usually a delta containing a few new characters or tokens of text.
A typical stream has a recognisable shape. It opens with an event announcing the start of the message and its metadata. A run of delta events follows, each appending text to the answer. When the model finishes, a final event reports why it stopped, for example because the answer was complete, a stop sequence was hit or the max tokens limit was reached. Many providers also send token usage at the end, which is the only point at which the full count of input and output tokens is known.
The client’s job is to read events as they arrive, append each delta to a buffer, and render the buffer. SDKs wrap this in an iterator or callback, so application code can loop over chunks rather than parse the raw event stream. Some providers and frameworks use WebSockets instead of SSE, particularly for voice and other two-way sessions, but the idea is the same.
Why streaming matters
The main benefit is perceived speed. A 500-token answer might take eight seconds to generate in full. Without streaming, the user stares at a spinner for all eight. With streaming, the first words appear after a short pause and the user reads at roughly the speed the model writes, so the wait mostly disappears from view. For interactive products this is the cheapest latency improvement available, because it changes nothing about the model or the prompt.
Streaming also lets users and systems react earlier. A user who sees the answer heading in the wrong direction can stop it and rephrase, which saves the remaining output tokens. A voice agent can start speaking the first sentence while the model is still writing the second, which is often the difference between a natural pause and an awkward silence. An application can check the opening of a response against guardrails and cut it off before it runs on.
For long-running work, a stream doubles as a progress channel. An agent loop can stream its intermediate steps, such as which tool it is calling and what it found, so a user watching a multi-minute task can see that it is working and what it is doing.
Streaming, latency and throughput
Streaming reduces perceived LLM latency, but it does not make generation faster and can slightly lower throughput, because each event adds a little overhead and the connection stays open for the whole response. For a single user waiting on an answer, the trade is clearly worth it. For bulk work with nobody waiting, it is not: batch inference returns complete results, often at lower cost, and there is no one to benefit from partial output.
Because streaming makes time to first token the latency users feel, it shifts attention to what happens before the first token. Prefill time grows with the size of the prompt, and any retrieval or memory lookup before the model call delays the first event too. A streaming product with a 20,000-token prompt can still feel slow, because users wait through the whole prefill before the first word appears.
Aspect | Streaming | Returning the full response |
|---|---|---|
When text reaches the client | As it is generated | After the last token |
Latency the user notices | Time to first token | Total response time |
Total generation time | About the same | About the same |
Handling in code | Event loop, partial state, mid-stream errors | One response to parse |
Best suited to | Chat, voice, interactive agents | Batch jobs, code that needs the whole result |
Streaming tool calls and structured output
Plain text is easy to stream because every prefix of a sentence can be shown. Structured output is harder. When a model calls a tool through function calling, the arguments arrive as fragments of a JSON string spread across many events. The client has to accumulate them and parse the arguments only once the tool call is complete, because a half-finished JSON object will not parse. Most SDKs do this accumulation for you and emit a single event when a tool call is ready.
The same applies to structured output and JSON mode. If your code needs the whole object, streaming adds complexity without much benefit, so many teams turn it off for those calls. If you want to show fields as they fill in, for example a summary appearing before a list of action items, you can use a partial JSON parser that tolerates incomplete input and re-renders as each chunk arrives. Validate against the JSON schema only once the stream has finished.
Agents often mix the two. A single response can contain some text, a tool call, and then more text after the tool result comes back. Clients need to handle each content block separately and keep them in order, which is one reason agent frameworks expose higher-level stream events such as step started, tool called and message completed.
Handling errors and interruptions
A stream can fail halfway. The connection can drop, the provider can return an overload error after the first few events, or a proxy can time out a long-lived connection. Unlike a single response, a failed stream leaves partial output on the screen, so the client needs a policy. Common choices are to keep the partial text and offer a retry, or to clear it and retry automatically with retry logic that backs off between attempts.
Cancellation needs care too. When a user presses stop, the client should close the connection so the provider stops generating and stops billing for output. If your own server sits between the client and the provider, make sure a cancelled client request also cancels the upstream call, or you will pay for tokens nobody reads.
Infrastructure between the model and the user can quietly break streaming. Some reverse proxies, load balancers and serverless platforms buffer responses until they finish, which turns a stream back into a single delayed response. Compression can have the same effect. If tokens arrive in one burst at the end during testing, check every layer for buffering before suspecting the model. An LLM gateway in the path needs to pass streams through rather than collect them.
Observability for streamed calls
Streamed calls need slightly different metrics from ordinary ones. Record time to first token, time to last token and the token rate in between, along with the stop reason and final usage counts from the last event. Agent observability tools that understand streams can capture these per call and roll them up per task. Watch for streams that end with a max-tokens stop reason, which usually means answers are being cut off, and for gaps between events, which point to provider load or buffering in your own stack.
A worked example
A team builds a voice assistant for a customer support line. Their pipeline turns the caller’s speech into text with speech-to-text, looks up what the assistant knows about the caller, calls the model, and sends the reply to speech synthesis. With the model returning full responses, callers hear silence for around three seconds after they finish speaking, most of it spent generating a reply of 80 to 120 words. These timings are illustrative.
They switch the model call to streaming and send text to speech synthesis one sentence at a time, starting as soon as the first sentence ends. The assistant now begins speaking roughly a second after the caller stops, and the rest of the reply is generated while the first sentence is being spoken. They also shorten the prompt by replacing the call history with a handful of retrieved facts about the caller, which brings the first sentence forward further, because the model has less input to process before it can start.
Two problems appear in testing. Their hosting platform buffered responses, which they fix with a configuration change. And callers sometimes interrupt, so they add cancellation that closes the model stream as soon as the caller starts speaking again. Both are typical of the work streaming adds.
Where Exabase fits
Exabase does not generate text, so it does not stream model output. It sits before the model call, where it affects how soon the first streamed token can arrive. Exabase Memory returns the facts relevant to the current request, with simple retrieval in about 200 milliseconds, so an agent can send a short prompt in place of a long history. Deep Search returns the passage that answers a question rather than several whole chunks. A shorter prompt means a shorter prefill, and in a streaming product that is the delay users notice.
For work that takes longer than a user should wait, Exabase uses asynchronous jobs rather than streams. Extract processes files in the background and can notify your server through a webhook when a job is done, as the extraction webhooks guide describes. Workers runs return a chat ID immediately, and you read the conversation once the run has finished, as covered in running Workers. Our post on why the webhook is the right interface for extraction explains the reasoning, and the webhooks vs polling entry compares the two notification patterns.
Frequently asked questions
What does streaming mean in an LLM API?
It means the API sends the model’s output in small chunks as it is generated, over one open connection, instead of returning the whole response at the end.
Does streaming make an LLM faster?
It makes it feel faster. Total generation time stays about the same, but users start reading as soon as the first token arrives, so the wait they notice is much shorter.
What protocol do LLM APIs use for streaming?
Most use server-sent events over HTTP, with one JSON event per chunk. Some real-time and voice APIs use WebSockets.
Can I stream structured output or tool calls?
Yes, but the JSON arrives in fragments. Accumulate the fragments and parse once the object is complete, or use a partial JSON parser if you want to show fields as they fill in.
Why are my streamed tokens arriving all at once?
Something between the model and the client is buffering the response. Reverse proxies, serverless platforms and response compression are the usual causes.
When should I not use streaming?
Skip it for batch jobs, background tasks and calls where your code needs the complete result before doing anything. Streaming adds handling complexity and helps only when someone is watching the output.
Does Exabase stream responses?
Exabase does not generate model output, so there is nothing to stream. Its retrieval calls return complete results quickly, and long jobs such as extraction run asynchronously with webhook notifications.
Related pages: time to first token, LLM latency, batch inference, structured output, function calling, voice agents use case, voice agents need memory, speech-to-text APIs compared, webhooks vs polling