LLM Token Counter & Cost Calculator
Count tokens exactly for OpenAI encodings, estimate Claude and Gemini usage honestly, measure what whitespace waste costs you, compare prompt versions and project monthly API costs for any model — including ones released after this page was written. Everything runs locally: your prompt never leaves the browser.
o200k_base
exactOpenAI's encoding for current flagship models, exact offline
—
cl100k_base
exactLegacy GPT-4 and GPT-3.5 encoding; also the baseline used for labelled estimates
—
Cost calculator
Add any model — including ones released after this page was written. Copy the input and output prices per million tokens from the vendor pricing page, choose how tokens are counted, and compare.
No models yet — add your first row to compare costs.
Prices change too often for any hardcoded table to stay honest. Instead, copy them straight from the source:
Your rows are stored only in the URL hash, so you can bookmark or share a configuration.
| Model | Tokens | Input $/1M | Output $/1M | Estimated cost | Context use |
|---|
What is a token?
A token is a chunk of text chosen by a model's tokenizer. Sometimes it is a whole word, sometimes part of a word, punctuation, whitespace or a byte sequence. In OpenAI's cl100k_base encoding, hello world is 2 tokens and tiktoken is great! is 6 tokens. There is no stable characters-per-token ratio across languages, code and formatting.
Why token counts differ between models
Tokenizers are trained with different vocabularies and merge rules. A compressed tokenizer can represent common English words in fewer tokens, while the same text may fragment in another vocabulary. Unicode, emoji, CJK text, indentation, repeated symbols and source code often expose the biggest differences. That is why copying a character-count heuristic into production cost estimates is unreliable.
Why Claude and Gemini are labelled as estimates
OpenAI publishes enough tokenizer information for compatible offline libraries to reproduce o200k_base and cl100k_base exactly. Anthropic does not publish the current Claude tokenizer for offline use, and its own tooling warns that older tokenizers are not exact for Claude 3 and newer models. Google also does not publish a browser-usable offline tokenizer for current Gemini models.
This calculator therefore makes a deliberate distinction every time you add a row: OpenAI encodings are counted exactly, while the Claude/Gemini option produces an estimate derived from cl100k_base and labels it as such. For billing-grade Claude or Gemini counts, use the vendor token-counting API. For planning, prompt compression and rough cost comparison, a clearly labelled estimate is more useful than a false exact number.
How to estimate an API call cost
The formula is simple: input tokens divided by one million times the input price, plus output tokens divided by one million times the output price. The hard part is estimating output length. A short classification answer may cost almost nothing, while a long code generation or reasoning response can cost more than the prompt. Use realistic completion lengths and measure production traffic before choosing a model.
| Cost component | Formula |
|---|---|
| Input cost | input tokens ÷ 1,000,000 × input price |
| Output cost | output tokens ÷ 1,000,000 × output price |
| Total estimate | input cost + output cost |
Example: what vendor pricing tables look like (snapshot, November 2026)
Prices and model lineups change every few months, so treat this table as a point-in-time example of the data you copy into the calculator — not as a reference to rely on. Always check the vendor pages linked above for current numbers.
| Model (Nov 2026) | Input $/1M | Output $/1M | Context |
|---|---|---|---|
| GPT-5.2 | $1.75 | $14.00 | 272K |
| GPT-5 mini | $0.25 | $2.00 | 272K |
| GPT-4.1 | $2.00 | $8.00 | 1M |
| Claude Opus 5.5 | $4.00 | $20.00 | 1M |
| Claude Sonnet 5.5 | $2.00 | $10.00 | 1M |
| Gemini 2.5 Pro | $1.25 | $10.00 | 1M |
| Gemini 2.5 Flash | $0.30 | $2.50 | 1M |
Frequently asked questions
How do I count tokens for OpenAI models?
Paste your prompt into the input box. The counter loads OpenAI-compatible o200k_base and cl100k_base encodings locally and shows exact token counts for those encodings without sending the text to a server.
Can I count Claude tokens exactly in a browser?
No. Anthropic does not publish the current Claude tokenizer for offline use, so an exact Claude count requires Anthropic's token counting API. This tool labels Claude counts as estimates derived from cl100k_base instead of pretending they are exact.
Can I count Gemini tokens exactly offline?
No. Google does not publish a browser-usable offline tokenizer for current Gemini models. Gemini counts are estimates derived from cl100k_base; use Google's countTokens API when you need billing-grade accuracy.
Where do I find current LLM API prices?
Model prices change frequently, so always use the vendor pricing pages: OpenAI, Anthropic and Google. Copy the input and output prices per million tokens into the calculator rows.
Why does the same text have different token counts across models?
Tokenizers split text using different vocabularies and merge rules. Punctuation, whitespace, Unicode, code, emoji and non-English text can tokenize very differently, so a prompt that fits one model may use a meaningfully different number of tokens in another.
How can I reduce the token count of a prompt?
The biggest cheap wins are removing repeated whitespace, collapsing excess blank lines and stripping trailing spaces — the waste analysis panel measures exactly how many tokens each pattern costs in your text. For larger savings, compare versions: rewrite the prompt more tersely, paste it as version B, and check whether the token delta is worth any quality change. At high request volumes even small per-prompt savings compound into meaningful monthly cost differences.
Does my prompt leave the browser?
No. Tokenization and cost calculation run entirely in client-side JavaScript. The prompt is not transmitted, logged or stored in the URL; only your calculator rows and settings are serialized into the hash so you can share or bookmark a configuration.
Related resources
- LLM Cost Optimization Guide — reduce token spend without degrading answer quality.
- OpenAI API Mastery Guide — production patterns for OpenAI applications.
- LLM Prompt Engineering Guide — structure prompts for reliability and efficiency.