What is a token?
Language models don't read characters or words. They read tokens, which are chunks of text from a fixed vocabulary. Common words are usually one token (“the”, “agent”), while rare words, code identifiers, and non-English text split into several. Everything about using an LLM API is measured in tokens: price, context-window limits, rate limits, and latency.
How this token counter works
- OpenAI (GPT-4o, GPT-5.x, GPT-6): exact counts from the
o200k_baseencoding, the same byte-pair encoding OpenAI'stiktokenlibrary uses. - Anthropic Claude: an estimated range. The older tokenizer (Sonnet 4.6, Haiku 4.5) is similar in size to
cl100k_base. The newer tokenizer in Opus 4.7 and later produces about 1.0–1.35× as many tokens. - Google Gemini: an estimated range based on
o200k_base, which is similar in vocabulary size to Gemini's SentencePiece tokenizer.
Tokens and context windows
The context window is the most tokens a model can take in one request, counting input and output together. The bar in each row shows how much of that window your text uses. For agents, remember that the system prompt, tool definitions, and every earlier tool result all share the same window, and that context grows with every step. Use the AI Agent Cost Calculator to see how that adds up.
Tips for reducing token usage
- Trim verbose system prompts and remove examples the model no longer needs.
- Keep tool schemas short: descriptions and JSON schemas are sent on every call.
- Return compact tool results (IDs and summaries, not full documents) and let the agent fetch details on demand.
- Turn on prompt caching for static prefixes. Cached reads cost 2.5–25% of the normal input price, depending on the provider.