See also / canonical cluster. Pillar for token & cost estimation: How to estimate LLM token costs before you ship. Interactive: token & cost estimator. This page stays on a different intent — see the intro.
This is the fundamentals spoke: what a token is, why model families disagree, and how counting relates to context windows. It is not the pre-ship monthly cost spreadsheet — that lives on the estimation pillar. Use the token & cost estimator when you need interactive numbers.
What is a token?
A token is a chunk of text produced by a tokenizer — often a subword piece. Rough intuition for English prose:
- ~4 characters per token
- ~0.75 words per token (or ~100 tokens ≈ 75 words)
These are rules of thumb, not laws. Code, URLs, non-English text, and whitespace-heavy JSON tokenize differently.
Chinese often uses fewer characters per token than a naive English rule suggests — still measure with a real tokenizer when precision matters.
Why vendors count differently
Each model family ships (or implies) a tokenizer. The same string can yield different token counts on different APIs. Therefore:
- Budget with the tokenizer of the model you call
- Do not reuse GPT heuristics blindly for other families
- When vendors expose
usage.prompt_tokensin responses, treat that as ground truth for billing
Offline estimators (including ours) approximate for planning. They are for forecasts and teaching, not invoices.
What consumes tokens in a request?
Typical chat/completions request:
- System message
- Developer / tool instructions (if any)
- Conversation history
- Retrieved documents / RAG chunks
- Tool schemas and tool results
- The new user message
- Output tokens from the model reply (billed separately, often at a different rate)
Agents multiply (4)–(6) across loop iterations. That is why research agents need max-call budgets (system prompts for research agents).
Context window vs cost
- Context window — hard maximum tokens the model can consider (input + output constraints vary by API)
- Cost — usually dominated by how many tokens you actually send and generate, not the maximum window
A 128k window does not mean you should send 128k tokens. More context is not free and often hurts quality when noisy.
Practical estimation workflow
- Paste a representative prompt (system + user + sample RAG) into an estimator
- Set expected output length (
max_tokensor observed average) - Multiply by monthly calls × (1 + retry rate)
- Apply vendor $/1M input and output rates
- Add 10–20% buffer for prompt creep
Do this per feature, not as one blob.
Why your estimator disagrees with the API
| Cause | What to do |
|---|---|
| Different tokenizer | Prefer API usage fields |
| Chat template tokens | Account for special tokens / role markers |
| Tools JSON | Schemas are not free |
| Invisible system additions | Log full request payload size in staging |
| Compression / caching | Cached tokens may bill at different rates |
Counting for non-English and code
- CJK text: do not assume 4 chars/token; sample real counts
- Code: operators and identifiers can be token-heavy; indentation matters less than you think, but long minified lines can be worse
- Base64 / hex: extremely token-inefficient — avoid stuffing blobs into prompts
- Markdown tables: usually fine; huge HTML dumps are not
Output token control
Output is often pricier per token than input on frontier models.
- Set
max_tokensto the task (titles vs essays) - Ask for compact formats (bullets, JSON without comments)
- Forbid restating the user question
- For creative tasks, accept higher caps deliberately — and budget them
Token budgets in product design
Examples:
- Free tier: 50k input tokens / day / user
- Support bot: hard cap 8k context; summarize older turns
- Doc assistant: top-5 chunks ≤ 3k tokens combined
- Eval suite: separate budget so it cannot starve production
See LLM cost control for teams.
Teaching teammates a shared language
Print this on the wiki:
- “We’re not short on ideas; we’re short on tokens and edit time.”
- “Expanding the system prompt by 1k tokens at 1M calls/month is a budget change — review it.”
- “Estimator ≠ invoice; API usage = invoice.”
Quick lab (10 minutes)
- Take a 500-word blog paragraph; estimate tokens at 4 chars/token
- Run the same text through your provider’s tokenizer or a library when available
- Compare error %
- Repeat with 50 lines of Python and a Chinese paragraph
- Update your team’s rule of thumb per content type
Related tools and guides
- LLM token cost estimation (cluster pillar)
- Token estimator tool
- Prompt cleaner — reduce junk tokens before counting
- Prompt engineering checklist
On this page · 12 sections
- What is a token?
- Why vendors count differently
- What consumes tokens in a request?
- Context window vs cost
- Practical estimation workflow
- Why your estimator disagrees with the API
- Counting for non-English and code
- Output token control
- Token budgets in product design
- Teaching teammates a shared language
- Quick lab (10 minutes)
- Related tools and guides
Hubs: All guides · Tools · Start here
Tool links point to free client-side utilities on this site. Third-party product links may be affiliates — affiliate disclosure.