What is a token?
Tokens are the smallest units of text a language model reads or writes, and every context limit and price is measured in them.
Guide details
- Type
- Explainer
- Reading time
- 2 min read
- Scope
- First rung of the agent fundamentals ladder: the base unit of model input and output.
A token is the smallest unit of text that a language model reads or writes. Before your prompt reaches the model, a tokenizer splits the input string into these pieces and maps each one to an integer id. The model only ever sees those ids, never raw characters.
Tokenization is not word-for-word. Frequent short words often become a single token, while rarer words split into fragments; punctuation and whitespace usually attach to neighboring pieces. Different model families use different tokenizers, so the same sentence can produce different token counts on different models.
Tokens have three practical consequences. Context windows are measured in tokens, so the combined size of your prompt and the model's reply has to fit inside that budget. API pricing is quoted per token, separately for input and output. And some text is disproportionately expensive: code, unusual spellings, and many non-English scripts expand into more tokens than their character count suggests.
Because counts are hard to eyeball, every major provider ships a tokenizer library or a counting endpoint. Measure a request before sending it: token math is the difference between a prompt that fits and one that is silently truncated.
Sources
- Understanding and counting tokens — OpenAI Help CenterofficialOpenAI
- Token counting — Anthropic DocsdocumentationAnthropic
Taxonomy
Concepts
Topics
Related content
- RelatedHow does chat work?Chat requests are assembled from text that models consume as tokens.
Referenced by
- RequiresHow does chat work?Message history is consumed as tokens and billed against the context window.
- Requires
Related
- How does chat work?Mellnx first-partyagent-fundamentals
A chat request is a stateless list of role-tagged messages, and your application owns the conversation history.
- What is an LLM?Mellnx first-partyagent-fundamentals
An LLM is a neural network trained to predict the next token, and that single mechanism is the engine every chat app and agent runs on.
- What is an AI agent?Mellnx first-partyagent-fundamentals
An AI agent is an LLM plus a harness plus tools running in a loop, with the model deciding each next step.