StackPractices

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.

1. Prompt or text

0 characters · 0 bytes · 0 words

Paste text to count tokens

2. Output & volume

Output tokens are usually the expensive half of a call. Use your expected completion length, not the model maximum.

Scales every cost to a monthly projection — per row, for whitespace waste and for A/B version deltas.

Privacy: tokenization runs locally in your browser. Your prompt is never transmitted and is not stored in the URL.

o200k_base

exact

OpenAI's encoding for current flagship models, exact offline

—

cl100k_base

exact

Legacy 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.

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 costinput tokens ÷ 1,000,000 × input price
Output costoutput tokens ÷ 1,000,000 × output price
Total estimateinput 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.00272K
GPT-5 mini$0.25$2.00272K
GPT-4.1$2.00$8.001M
Claude Opus 5.5$4.00$20.001M
Claude Sonnet 5.5$2.00$10.001M
Gemini 2.5 Pro$1.25$10.001M
Gemini 2.5 Flash$0.30$2.501M

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