How Does an LLM Actually Write?
One token at a time, each conditioned on everything before it. The generation loop explains streaming, cost, and why models cannot revise.
Try it before reading further
Build a continuation one step at a time · 5 minOn this page
The whole sequence so far is fed back in. The model predicts one token — Paris — appends it, and runs again.
A model does not compose a response. It builds one forward, one token at a time, with no plan and no ability to revise.
That single fact explains streaming interfaces, conversation costs, why chain-of-thought prompting works, and why a model sometimes paints itself into a corner and keeps going.
The loop
Say you send The capital of France is.
Step 1. The model processes the sequence and outputs a probability distribution over its entire vocabulary. ␣Paris gets most of the mass; thousands of other tokens split the remainder.
Step 2. A sampling step picks one token. Say ␣Paris.
Step 3. That token is appended. The sequence is now The capital of France is␣Paris.
Step 4. The whole thing goes back in. Predict again.
Repeat until the model emits a stop token or hits a length limit. A 500-token answer means 500 passes through the network.
This is what autoregressive means: each output becomes part of the next input.
Four consequences
It cannot revise
Once a token is emitted it is fixed. The model cannot go back and change it.
Watch what this causes. If a model starts The three main causes are: and only two good causes exist, it will invent a third — the sentence structure committed it. Human writers delete the sentence. The model cannot.
This is one mechanical root of hallucination: not ignorance, but commitment to a structure that now requires content.
Thinking out loud actually helps
Each token gets one forward pass of computation. A hard question answered in one token gets one pass of thinking.
But if the model writes out intermediate steps, each step is a token, and each token gets its own pass — with all previous steps visible as input. The generated text becomes working memory.
That is why "think step by step" is not a psychological trick. It converts a single-pass problem into a multi-pass one. See Making a Model Think Step by Step.
Streaming is the natural output
Tokens are produced sequentially, so they can be shipped as they appear. Streaming is not a UI flourish layered on top; it is the raw shape of the process. See Why Responses Stream.
Conversation cost grows with the square
The model has no memory between calls. Each turn re-sends the entire history as input.
Turn 1 sends 100 tokens. Turn 2 sends 100 + response + new question. Turn 10 re-sends everything nine turns produced. Total tokens across an n-turn conversation grow with n², not n.
This is why a single long document can be cheaper than a short chat, and it is what KV caching exists to soften.
Where the randomness comes from
If step 2 always took the highest-probability token, output would be deterministic — and noticeably worse. Greedy selection produces repetitive, flat text that gets stuck in loops.
So a sampling step deliberately introduces randomness. That is why the same prompt gives different answers each time, and it is a design choice rather than a defect. Temperature and Top-p covers the controls.
Stopping
Three ways generation ends: the model emits a special end-of-sequence token it learned during training; a maximum token limit is reached; or you specify a stop sequence and the API cuts off when it appears.
Truncated output usually means the second one. Raise the limit or ask for less.
What to remember
- Generation is a loop: predict a distribution, sample a token, append, repeat.
- No revision — a committed structure must be filled, which is one root of hallucination.
- Each token gets one forward pass, so written-out reasoning genuinely adds computation.
- Conversation cost grows with the square of length, because history is re-sent every turn.
Next: Temperature and Top-p, Explained — the knobs on step 2.