A language model writes its answer one token at a time. You can wait for the last token and show the whole answer at once, or show each token the moment it’s written. That second option, streaming, doesn’t make the answer arrive any sooner, but it changes how long people sit staring at nothing. Streaming doesn’t make the model faster; it makes the wait shorter. Here you’ll replay a real answer both ways, and see what decides how long the first word takes.
The same answer, two ways#
We asked a small open model, Qwen3-1.7B, running on a laptop-class CPU, what to check when a new thermostat’s screen stays dark, and recorded the moment each token of its answer arrived. The figure replays those real timings: on the left the app waits for the whole answer, on the right it streams.
Predict first
Without streaming, this answer appears all at once after 7.2 seconds. With streaming, when does the first word appear?
Both versions finish at 7.2 seconds: streaming doesn’t make the model write a single token faster. What it removes is six seconds of blank screen. A blank screen feels much longer than the same time spent reading, and by the time the waiting version shows anything, the streaming reader has already seen the whole answer arrive. This answer is short. For longer ones the gap grows: a hosted model writing 50 tokens a second needs around 15 seconds for a 600-word answer, and nobody wants to stare at a spinner for that long.
Two phases: reading, then writing#
Every request has two parts. First the model reads the whole prompt in one go, called prefill; only then can it produce the first token. The wait until then is the time to first token (TTFT). After that it writes one token at a time, called decoding, at a fairly steady number of tokens per second. Streaming hides the decoding time; it can’t hide the prefill.
Predict first
Now the app puts 50 help-centre articles, about 2,700 tokens, in front of the same question. What happens to the wait for the first word?
The wait for the first token grows with the prompt: 0.9 seconds for the question alone, then 4.9 with 6 articles, 7.3 with 12, 14.6 with 25 and 25.0 with 50, roughly 100 prompt tokens read per second on this CPU. Writing slows only a little, from 4.7 to 3.4 tokens a second, because each new token also looks back over a longer prompt. The articles bought a better answer: generic advice became Hearth’s real fix, the C-wire and the circuit breaker. A GPU reads prompts far faster than this CPU, but the shape holds: long retrieved contexts, long chat histories and big system prompts all delay the first word. What helps is sending fewer, better passages, trimming the history, and prompt caching, which can cut the reading time for a prompt start the provider has seen recently.
Making a stream feel good#
- Show something at once. Even before the first token, show that the request was received: a typing indicator, or the user’s message moved into the chat.
- Let people stop it. A stop button cancels the request, so nobody waits for an answer they can already see is wrong, and you stop paying for tokens nobody reads.
- Render as it arrives, carefully. Answers often contain Markdown, and a half-finished table or code block can flicker. Render complete lines, or tolerate unclosed formatting until the end.
- Plan for failure halfway. A stream can break after 200 tokens. Keep what arrived, show an error, and offer to retry, rather than wiping the screen.
- Don’t stream what you must check first. If an answer has to pass a filter or be valid JSON before anyone sees it, streaming it to the screen defeats the check. Stream to your code, check, then show.
In code#
Streaming from a local model with Hugging Face transformers, free and local (pip install transformers torch). The model writes in a background thread and the loop prints each piece as it arrives:
import time
from threading import Thread
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
name = "Qwen/Qwen3-1.7B"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)
messages = [{"role": "user", "content": "In two sentences: why do chat apps stream their answers?"}]
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
inputs = tok(text, return_tensors="pt")
streamer = TextIteratorStreamer(tok, skip_prompt=True, skip_special_tokens=True)
start = time.time()
Thread(target=model.generate, kwargs=dict(**inputs, streamer=streamer, max_new_tokens=80, do_sample=False)).start()
first = None
for piece in streamer: # each piece arrives as soon as the model has written it
if first is None:
first = time.time() - start
print(piece, end="", flush=True)
print(f"\n\nfirst words after {first:.1f} s, finished after {time.time() - start:.1f} s")
# Chat apps stream their answers to provide real-time interaction and keep users engaged. This allows for a more dynamic and responsive experience.
#
# first words after 1.7 s, finished after 8.3 sYour times will differ: the first call includes some warm-up, and every machine is different. The pattern won’t: words start arriving long before the answer is finished.
What to remember
- Streaming shows each token as it’s written: the total time stays the same, but people see the first words almost at once.
- The wait before the first token is the model reading the prompt (prefill); it grows with the prompt, so long RAG contexts delay the first word even when streaming.
- Stream with care: a stop button, rendering that copes with half-finished text, a plan for broken streams, and no streaming of answers you must check first.