Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How LLMs Behave  ›  Lesson

Tokens and the Context Window

Tokens 12 minModels read and write in tokens, and the context window caps how many tokens of input and output fit in one call.

Tokens and the Context Window

The owner had an idea: paste the shop's entire 300-page parts catalogue into every triage prompt, "so the model knows everything". The API rejected the request as too long. Even a shorter catalogue would have made every email slow and costly to process. Both problems come from the same two ideas: tokens and the context window.

The rule

Models count in tokens, and input plus output must fit one window.

Tokens are the units a model reads and writes. Common words are often one token; rare words, names and numbers split into several. For English, a rough rule of thumb is about four characters, or three quarters of a word, per token. Other languages and code can use noticeably more tokens for the same meaning.

"Spoke & Chain"      ->  Sp | oke | & | Chain     (about 4 tokens)
"derailleur"         ->  der | ail | leur         (about 3 tokens)

Exact splits vary by model, so treat these as illustrations, not facts to memorise.

The context window is the maximum number of tokens the model can handle in one call. It is shared: the system instructions, the chat history, pasted documents, your question and the model's reply all count against the same limit.

Tokens matter for three practical reasons:

  • Cost — paid APIs usually charge per token, in and out.
  • Speed — more tokens take longer to read and to generate.
  • Attention — a key fact buried in a very long input is easier for the model to overlook than one in a short, focused prompt.

The shortcut

Treat the window as a budget: fixed instructions + variable input + room for the answer must stay under the limit, with a margin.

Budgeting the triage promptStep 1 of 4
  1. Fixed part

    Instructions, label definitions and examples: about 600 tokens, the same on every call.

The trap is thinking "bigger window, so paste everything". Even when it fits, stuffing the prompt costs money on every call and dilutes the facts that matter. Include what the task needs, and no more.

Drills

Answer fast — trust the rule.

quick drill

What is a token?

quick drill

What must fit inside the context window?

quick drill

Roughly how many tokens is a 400-word English email?

quick drill

The full catalogue fits in the window. Why still avoid pasting it into every triage call?

Remember

  • Models count in tokens, and input plus output must fit one window.
  • Shortcut: budget fixed instructions + variable input + answer room.
  • Trap: pasting everything just because it fits.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainBudget the window

The shop wants to paste its whole 300-page parts catalogue into every triage prompt. Explain the token and context-window problems with this, and suggest a better approach.