Flashcard: what is a token in LLM prompting and why does it matter for cost and context?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
A token is the model's subword unit of text, roughly 0.75 English words, and it is the unit both API pricing and context-window limits are measured in.
Imagine a typewriter that can only press one of fifty thousand pre-cut stamps instead of individual letters. Each stamp is a token. Some stamps are whole common words like the or apple, others are partial pieces like tion or ing, and others are single characters for rare symbols. To write any sentence the typewriter has to find the right sequence of stamps. When you ask an LLM a question, the model first turns your text into a sequence of these stamps, then predicts the next stamp, then the next, then the next, until it stops. The price you pay is per stamp pressed, both for reading your input and writing its reply. The maximum number of stamps the typewriter can hold in memory at once is the context window.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6 min: define tokens as subword units, give the 0.75-words conversion, separate input vs output pricing, explain the context-window budget, name the non-English and code penalty, point to tokenizer libraries.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Estimating token count by multiplying word count by 1.0 and being surprised when a code-heavy or non-English prompt blows the context-window budget; tokens are not words.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.