AI Token Counting: What Developers Need to Know (2026 Guide)
Understand AI tokens, how they're counted, and why they determine your API costs. Practical guide to estimating tokens, reducing usage, and picking cost-efficient models.
· Updated · 7 min read

Every AI API charges by the token. One token is roughly 4 characters or three-quarters of a word on most tokenizers. A 1,000-word blog post is about 1,300 tokens, and more on Claude's current tokenizer (see below). Understanding tokens is the difference between a $20/month AI bill and a $200 one.
This guide explains how tokens work, how to count them, and how to optimize your usage to keep costs down.
What Is a Token?
A token is the smallest unit of text that a language model processes. Models don't read characters or words. They read tokens, which are fragments of text determined during training.
Rough conversion rules:
| Text | Approximate Tokens |
|---|---|
| 1 word (English) | ~1.3 tokens |
| 1 sentence | ~15-25 tokens |
| 1 paragraph | ~60-100 tokens |
| 1 page (500 words) | ~650 tokens |
| 1,000 words | ~1,300 tokens |
| Average email | ~200-400 tokens |
| Average code function | ~100-300 tokens |
These are averages for English text on OpenAI-style tokenizers. Code, JSON, and non-English languages tokenize differently, and Claude's current tokenizer produces more tokens for the same text: Anthropic puts 1M tokens at roughly 555,000 words (Anthropic's model overview).
How Token Counting Works
Models use a tokenizer (like BPE, Byte Pair Encoding) to split text into tokens. Common words become single tokens. Rare words get split into multiple tokens.
Examples (OpenAI's o200k_base encoding):
- "hello" → 1 token
- "unbelievable" → 3 tokens ("un" + "bel" + "ievable")
- "GPT-5.6" → 5 tokens
console.log("hello")→ 5 tokens- A JSON object
{"name": "John"}→ 6 tokens
Key insight: Structured formats (JSON, XML, code) use more tokens per "meaningful unit" than natural language. A 10-row CSV is more token-efficient than the same data as JSON.
Input Tokens vs Output Tokens
AI APIs charge separately for:
- Input tokens: everything you send (system prompt, user message, context)
- Output tokens: everything the model generates in response
Output tokens are typically 2-6x more expensive than input tokens (prices from Artificial Analysis, September 2026):
| Model | Input/1M | Output/1M | Ratio |
|---|---|---|---|
| GPT-6 Luna | $0.10 | $0.50 | 5x |
| MiMo-V2.6-Pro | $0.43 | $0.87 | 2x |
| Gemini 3.8 Flash | $0.75 | $3.75 | 5x |
| Grok 4.7 | $2.00 | $6.00 | 3x |
| GPT-6 Sol | $2.00 | $10.00 | 5x |
| GPT-5.6 Terra | $2.00 | $12.00 | 6x |
| Claude Opus 5.5 | $4.00 | $20.00 | 5x |
Optimization implication: Reducing output length saves more money than reducing input length. Ask for concise responses. Use structured output (JSON mode) to avoid verbose explanations.
How to Count Tokens
Quick Estimation
- Count words × 1.3 = approximate tokens (English text)
- For code: count characters ÷ 3.5 = approximate tokens
- For JSON: count characters ÷ 3 = approximate tokens
Exact Counting
Use the tokenizer or counting API that matches your model:
- OpenAI models:
tiktokenlibrary (Python). GPT-5 models use theo200k_baseencoding; OpenAI hasn't said which tokenizer GPT-6 uses - Claude models: Anthropic doesn't publish a local tokenizer, so use its token counting API
- Gemini: Google's countTokens API
import tiktoken
enc = tiktoken.get_encoding("o200k_base") # the GPT-5 tokenizer
tokens = enc.encode("Your text here")
print(f"Token count: {len(tokens)}")
Our token counter tool gives you an instant estimate without writing code. It's exact for GPT-5 models and estimated from each provider's published ratio for the rest.
Context Windows Explained
The context window is the maximum number of tokens a model can process in a single conversation (input + output combined).
| Model | Context Window | In Words (~) |
|---|---|---|
| DeepSeek R1 | 64K | ~49,000 |
| Grok 4.7 | 500K | ~384,000 |
| Claude Opus 5.5 | 1M | ~555,000 |
| Gemini 3.8 Flash | 1M | ~769,000 |
| GPT-6 Sol | 1.05M | ~808,000 |
Word counts use 1.3 tokens per word, except Claude Opus 5.5, where Anthropic's docs give about 555,000 words per 1M tokens on its current tokenizer. GPT-6 Sol's 1.05M window allows up to 922,000 input tokens (OpenAI's model docs).
Larger context = more data per request, but also higher costs (you pay for all input tokens). Don't stuff the context window "just in case." Only include what's relevant.
Why Token Efficiency Matters
Some models use far more tokens to accomplish the same task. Artificial Analysis records what each model spent per task running its Intelligence Index, thinking tokens included:
- GPT-6 Astra (max effort): about $3.26 per task
- Claude Fable 5.1 (max effort): about $7.63 per task
Both list at $10/$50 per million tokens and score 53 on the index. Fable 5.1 costs more than twice as much per task because it writes more tokens to get there. At everyday settings, Grok 4.7 writes nearly three times as much as a typical model, which is why its low $2/$6 list price doesn't make it cheap per task. Check the full numbers on our benchmark dashboard.
7 Ways to Reduce Token Usage
1. Shorten your system prompt
System prompts are sent with every request. A 2,000-token system prompt across 100 daily requests = 200K extra input tokens/day. Trim it to essentials.
2. Use structured output
Ask for JSON or bullet points instead of prose explanations. A model generating a 500-word explanation uses ~650 output tokens. The same information as JSON might be ~150 tokens.
3. Cache repeated context
Use prompt caching (available on OpenAI and Anthropic) to avoid re-processing the same system prompt and context. Cache reads cost 90% less than fresh input on most models, and 95% less on Claude Opus 5.5.
4. Chunk large inputs
Instead of sending a full document (100K tokens) every request, extract the relevant section first. Use embeddings or simple keyword matching to find the right chunk.
5. Use cheaper models for simple tasks
A tiered approach routes simple tasks (summaries, formatting, classification) to budget models while reserving expensive models for tasks that need them. See our cost comparison guide.
6. Set max_tokens on output
Always set a max_tokens limit appropriate to your task. Without it, models may generate unnecessarily long responses.
7. Batch similar requests
Group multiple small tasks into a single request when possible. One request with 5 questions is cheaper than 5 separate requests (less system prompt repetition).
Token Costs for Common Tasks
| Task | Avg Input Tokens | Avg Output Tokens | Cost (GPT-6 Luna) | Cost (Sonnet 5) |
|---|---|---|---|---|
| Email draft | 300 | 200 | $0.0001 | $0.003 |
| Code function | 500 | 300 | $0.0002 | $0.004 |
| Blog paragraph | 200 | 400 | $0.0002 | $0.004 |
| Data analysis (1 page) | 2,000 | 500 | $0.0005 | $0.009 |
| Full article | 1,000 | 2,000 | $0.0011 | $0.022 |
| Code review (file) | 5,000 | 1,000 | $0.0010 | $0.020 |
| Agent task (complex) | 30,000 | 15,000 | $0.0105 | $0.210 |
GPT-6 Luna costs $0.10/$0.50 per million tokens and Sonnet 5 costs $2/$10. These figures leave out thinking tokens, which are billed as output and can multiply the output cost on reasoning models.
Summary
Tokens are the currency of AI APIs. Understanding them lets you:
- Estimate costs before committing to a model
- Optimize prompts to reduce waste
- Choose the right model tier for each task
- Set appropriate context and output limits
The fastest way to check your token usage: paste text into our token counter. For cost estimation across models, use the Cost Calculator. To see how token pricing varies across all major LLMs, check the LLM Leaderboard.


