LLM Token Counter & API Cost Calculator
Estimate tokens across Claude, GPT-4o / o3 / GPT-5, Gemini, and Llama, inspect visual token splits, check context windows, and compare monthly API costs
Free, no signup — tokenized in your browser, never uploaded.
- Est. Tokens (Claude)
- 187
- Anthropic BPE · offline approx
- Words
- 101
- Characters
- 683
- 581 no spaces
- Lines
- 13
- Chars / Token
- 3.7
Across model families
- Claude (Anthropic BPE)
- ~187
- GPT o200k (o200k_base)
- ~160
- Gemini (SentencePiece)
- ~160
- Llama 3/4 (Tiktoken 128K)
- ~173
Offline BPE heuristic — zero text leaves your browser. Use each provider's API tokenizer when exact billing precision is required.
Context window usage
Multi-Model API Cost Comparison
Compare input, cached-input, and output costs across frontier models. Every $/MTok rate below is editable.
| Model | Est. Tokens | Input $/MTok | Cached $/MTok | Output $/MTok | Per Request (Std) | Per Request (Cached) | Monthly (10,000) |
|---|---|---|---|---|---|---|---|
| Claude Opus 5.5 | 187 | $0.0026 | $0.0019 | $26.28 | |||
| Claude Sonnet 5.5 | 187 | $0.0013 | $0.0010 | $13.14 | |||
| Claude Haiku 5.5 | 187 | $0.000066 | $0.000049 | $0.657 | |||
| GPT-5 | 160 | $0.0010 | $0.0008 | $10.00 | |||
| GPT-4o | 160 | $0.0012 | $0.0010 | $12.00 | |||
| OpenAI o3 | 160 | $0.0010 | $0.0007 | $9.600 | |||
| Gemini 2.5 Pro | 160 | $0.0010 | $0.0009 | $10.00 | |||
| Gemini 2.5 Flash | 160 | $0.0002 | $0.0002 | $2.480 | |||
| Llama 4 Maverick | 173 | $0.0001 | $0.000096 | $1.172 |
How LLM tokenization works
Large language models do not read text one word or one character at a time. Before inference, a subword tokenizer splits your prompt into chunks called tokens: short common words stay whole (often including their leading space), longer or rare words split into stems and suffixes, punctuation and code operators become their own tokens, and multi-byte emoji or CJK characters can take more than one token.
As a quick rule of thumb for English prose, 1 token ≈ 4 characters (or roughly 0.75 words, so 1,000 tokens is about 750 words). Dense JSON, minified code, URLs, and non-Latin scripts consume noticeably more tokens per word. Turn on Highlight tokens above to see the exact boundaries across your own prompt.
Tokenizer differences across model families
| Model Family | Tokenizer | Vocab | Offline Approximation Notes |
|---|---|---|---|
| Claude (Anthropic) | Anthropic BPE | ~65K | Offline BPE heuristic tuned to Claude (~3.7–4.0 chars/tok English). Claude 4.7 and later use a newer tokenizer that can produce up to ~30% more tokens; exact billing uses Anthropic count_tokens. |
| GPT-4o / o3 / GPT-5 | o200k_base | 200K | Offline approximation of OpenAI o200k_base (merges longer English words, indentation & CJK more densely). |
| Gemini 2.5 | SentencePiece | 256K | Offline SentencePiece approximation tuned to Gemini 2.5 (~4 chars/tok English, efficient multilingual & code). |
| Llama 3 / 4 | Tiktoken 128K | 128K | Offline approximation of Meta Llama 3/4 128K BPE tokenizer (~3.9 chars/tok English). |
Estimating monthly LLM API spend
Real production bills depend on three levers: how many input tokens you send, what share of that prefix hits a prompt cache, and how verbose the model’s completion is. Adjust the Expected output ratio and Monthly requests above to model everything from short classification replies (0.25×) to long code-generation turns (2×).
Building specifically on Anthropic’s Messages API? Open the Claude Token Counter & Prompt Cache Calculator to split your cached CLAUDE.md or system context from per-turn user messages and compare 5-minute caching, 1-hour caching, and the 50% Batch API discount side by side.
Frequently Asked Questions
Does this token counter upload my prompt or code to a server?
No. Tokenization, token-boundary highlighting, context-window calculations, and API cost comparisons all run locally in your browser with JavaScript. Zero bytes of your text are sent to MarkdownTools or any AI provider.
How accurate is an offline browser token estimate compared to API billing?
Modern LLMs use slightly different subword vocabularies (Byte-Pair Encoding or SentencePiece). On English prose and standard source code, this client-side BPE heuristic typically lands within 3–8% of exact provider counts. Whenever exact billable counts matter — such as staying just under a hard rate limit — verify against the provider’s official count_tokens endpoint.
Why do Claude, GPT-4o / GPT-5, Gemini, and Llama report different token counts for the same text?
Larger vocabularies merge longer words, common indentation spaces, and non-Latin characters into fewer tokens. OpenAI’s o200k_base (200K vocab) and Gemini’s SentencePiece (256K vocab) therefore pack code and CJK text slightly more densely than Claude’s ~65K vocabulary.
What is the difference between Input, Cached Input, and Output pricing?
Input tokens cover everything you send to the model (system prompt, tool definitions, retrieved context, and user messages). Cached Input applies when a repeated prompt prefix hits the provider’s prompt cache (often 50–97.5% cheaper). Output tokens are generated by the model and usually cost 3× to 8× more per million tokens than input tokens.
Can I edit the $/MTok prices in the comparison table?
Yes. Click any Input, Cached, or Output $/MTok cell in the cost table to override the reference rate with your enterprise discount, regional tier, or updated model pricing. Your custom rates stay saved in your browser until you click Reset reference prices.
Need Anthropic prompt caching (5-minute vs 1-hour TTL) and Batch API math?
Use our dedicated Claude Token Counter, which separates your cached System Prompt from your uncached User Message and calculates exact dollar and percentage savings across 5-minute caching (1.25× write), 1-hour caching (2× write), each model’s cache-read rate (0.1× on most, 0.05× on Opus and Sonnet 5.5), and the 50% Batch API discount.