Token
The unit a model reads and writes: roughly a short word or a fragment of one, so a page of English is about 500 to 800 tokens. Tokens are what context windows are measured in and what API pricing is billed on, which is why context is treated as a budget.
At a glance
- Roughly
- A short word or word fragment
- Produced by
- The model's tokenizer
- Measures
- Context size, cost, rate limits
- Billed as
- Input and output separately
- Varies by
- Model family and language
How it works
A tokenizer splits text into pieces from a fixed vocabulary, usually built with a method like byte pair encoding. Common words become one token, rare words split into several fragments, and whitespace and punctuation are tokens too. The model never sees letters, only a sequence of token IDs.
Code tokenizes differently from prose. Indentation, braces, long identifiers like getUserSessionFromCookie, minified bundles, and base64 strings all break into many small tokens. A lockfile or generated JSON fixture can cost far more than its line count suggests.
Each model family can ship its own tokenizer, so the same file produces different counts on different models. Non-English text often splits into more tokens per word than English, and emoji or unusual Unicode can take several tokens per character. When you need a real number rather than an estimate, run the text through the provider's tokenizer or token counting endpoint.
Why it matters
Everything in an agent session is tokens: the system prompt, tool definitions, every file read, every command output, every reply. It all accumulates in the context window, and on API pricing you pay for it, typically with output tokens priced higher than input. Because an agent resends the conversation each turn, one large tool result keeps costing you on every later request until the session ends or is compacted. That is the practical case for targeted searches, truncated logs, and subagents.
On a flat-rate subscription the cost shows up differently: as usage limits you hit sooner. Either way, a session that reads less and says less gets more work done per window.
Token vs. context window
A token is the unit; the context window is the capacity measured in that unit, counting both the input and the reply being generated. Subscription usage limits and API rate limits are also expressed in tokens, so one unit governs what fits, what it costs, and how fast you can go.
Common mistakes
- Assuming one token equals one word, when the ratio shifts with language, content type, and tokenizer.
- Reading lockfiles, build output, or whole log files into an agent session and paying for them on every later turn.
- Treating a large context window as free room, when models tend to use information less reliably as the window fills.
Related terms
Frequently asked questions
How do I count tokens accurately?
Use the provider's tokenizer library or token counting endpoint for the specific model. Rules of thumb do not transfer between model families.
Why are output tokens more expensive than input tokens?
Output is generated one token at a time, each needing its own pass through the model, while input can be processed in parallel. Providers price that difference into their rates.
Do tool results count as tokens?
Yes. Anything returned into the conversation, including file contents and command output, is tokenized and counts against the context window and the bill.