How AI works

How the answer is created

One token at a time, a little randomness, thinking first, and tools.

6 min3 / 4

The answer is not fetched from a drawer. It is built on the spot, piece by piece. You can actually watch this happen: the text appears word by word on your screen because that is exactly how it is produced.

One token at a time

  1. After reading the whole context, the model calculates a probability for every in its vocabulary: how likely is each one to come next?
  2. One token is picked, usually one of the most likely.
  3. That token is added to the text, and the model runs again with the longer text.
  4. This repeats hundreds or thousands of times until the model produces a special “end” token.

Try it yourself with the simplified demo below. The bars show how likely each next word is. Pick a word and watch the sentence grow.

Next-word predictor

A toy version of what the model does for every token. The probabilities are made up for illustration.

The cat sat on the …

mat31%
sofa23%
floor17%
windowsill13%
roof8%
keyboard7%
moon1%

0 = always the top word. Higher = more surprises.

Why the same question gives different answers

If the model always took the single most likely token, its writing would be flat and repetitive. So there is a bit of controlled randomness, set by a value called temperature. Low temperature means predictable and focused, high temperature means more varied and creative, and too high means nonsense. The apps choose a sensible setting for you, which is why asking the same thing twice gives two slightly different answers.

Thinking before answering

Modern models can first write out their reasoning before the actual answer, like notes on a scratchpad. These thinking tokens let the model work through a problem step by step. On current Claude models such as Opus 5.5, this thinking is always on, and the effort setting controls how much of it happens. That is why a hard question takes longer: the model is literally writing more before it answers.

A scratchpad, not a windowThe visible reasoning is useful, but it is not a perfect view of what happens inside the model. Research has shown that a model's explanation of its own steps can differ from what it actually did. Judge the answer, not only the reasoning.

Tools: when the model needs something it does not have

A model can also write a special request instead of normal text, such as “search the web for…”, “run this code” or “read this file”. The app carries out the request, puts the result into the context, and the model continues writing with that new information. Web search, file creation and connectors all work this way.

Model writes a request“search: museum opening hours Lisbon”
→
App runs the toolSearch, code, file, connector.
→
Result goes into the contextThe model keeps writing with it.
The model never visits the web itself. It only reads what the tool brings back.

This explains two things from earlier lessons. First, search results are simply more text in the context, so the answer is only as good as the sources found. Second, text from a web page can contain hidden instructions, which is why is a real risk.

One piece at a time, but with a plan

“One token at a time” sounds short-sighted, but it is not the whole story. When Anthropic looked inside Claude, they saw it choose a rhyme word before writing the line that ends with it. So the model can aim at a goal several words ahead, even though it writes the words in order.

Try it now: Ask the same creative question in three new chats, for example “Give me a name for a small bakery”. Compare: what stays the same, and what changes?

Check yourself

1. How is an answer produced?
2. What does a higher temperature do?
3. Why does a hard question take longer to answer?
4. How does web search get into an answer?

Tip: use ← and → to move between lessons.