How it works · 4 of 37 Foundation

What are tokens and the context window in an AI model?

The model's desk

Tokens & the context window: Text is cut into tokens (word pieces); a model can only read a fixed number at once: its context window.

Loading the animation…

Say it like this A model knows general things from training, but your exact facts must sit on its desk, the context window, which holds a fixed number of tokens; whatever falls off, it cannot see.

Under the hood — for builders
Real tokens, from GPT-4o's tokenizer
A token is a piece of text the model reads as one unit. The policy line from this card, cut by the real tokenizer (· marks a space):
Context window: how many tokens fit at once
Everything sent with a question (instructions, chat so far, retrieved pages) must fit. Drawn to scale:
Billing
APIs charge per token, quoted per million. The whole prompt is sent again on every call.
Watch out
Some languages need up to 15× the tokens for the same text (Petrov et al., 2023): costlier, fills sooner.
Measure it
tiktoken, or your provider's token-counting tool, before sending a prompt.
Sources
Sennrich et al., byte pair encoding (ACL 2016) · tiktoken · Petrov et al. (NeurIPS 2023) · Liu et al., Lost in the Middle (2023).

What happens in the tokens & the context window animation, step by step?

  1. Models don't read words. Text is cut into tokens: a common word is usually one token, a rarer word several.
  2. For each question, the model reads from a desk with room for a fixed number of tokens: its context window. (Real desks hold tens of thousands or more; we draw 16.)
  3. Everything sent with the question shares this desk: instructions, the chat so far, your pages. When it's full, the oldest tokens fall off.
  4. Ask about refunds now. "14 days" fell off, so the model falls back on what it learned in training, and guesses "30 days".
  5. So a model has two sources: training (general, public, stops at a date) and the desk (your exact facts). RAG puts the right page on the desk.
  6. Your turn: drag the desk size and watch what fits.

What everyday example explains tokens & the context window?

An expert at a desk. They know a lot in general (training), but your policy is in the filing cabinet: they can read it only once someone (RAG) puts that page on the desk.

Why should a team care about tokens & the context window?

Sets cost, and why retrieval picks only a few pieces.