Free LLM Token Counter – GPT, Claude & Gemini API Cost Calculator | TrenTyx

trentyx@local:~/dev-utilities/token-counter $ run token-counter_

Count the tokens in a prompt, see how much of the context window it uses, and estimate what the API call will cost across GPT, Claude and Gemini models. The fast estimator runs offline; load the exact OpenAI tokenizer on demand when you need byte-perfect counts.

prompt.txt 0 characters
0
tokens (estimated)
0
characters
0
words
0.00
characters per token
0
UTF-8 bytes
Counting Mode
context window: — tokenizer: fast estimate (offline)
cost-estimate
Input tokens$0.000000
Output tokens$0.000000
Cost per call$0.000000
Cost for 1,000 calls$0.00
token-preview first 400 segments
Enter some text to see how it splits into tokens.

How LLM Tokens Work

Language models do not read characters or words — they read tokens, sub-word chunks produced by a byte-pair encoding tokenizer. In English, a token averages roughly four characters, so 1,000 tokens is about 750 words. Code, JSON, non-Latin scripts and emoji are far denser: a single emoji can cost three or four tokens, and Chinese or Japanese text often costs about one token per character.

Tokens matter for two reasons. First, every model has a fixed context window, and prompt plus response must fit inside it. Second, you are billed per token, with output tokens typically priced four to six times higher than input tokens — which is why an accurate estimate of the response length matters as much as the prompt itself.

Estimate Mode vs Exact Mode

The default fast estimate runs entirely offline. It splits your text the way a BPE tokenizer would — word runs, digit groups of three, punctuation, whitespace and script-aware handling of CJK and emoji — then applies a per-family calibration factor. For ordinary prose and code it typically lands within about 10% of the real count, which is accurate enough for budgeting.

When you need the real number, switch to exact mode. The page then downloads the official OpenAI BPE vocabulary (roughly 2 MB, cached by your browser afterwards) and tokenises with it. Exact mode covers OpenAI models; Anthropic and Google do not publish browser-runnable tokenizers, so those models always use the calibrated estimate. If the download fails — for example on an offline machine or behind a strict firewall — the tool says so and falls back to the estimator instead of showing a wrong number.

Common Use Cases

  • Budgeting a feature before you build it — paste a representative prompt, set the expected output length and call volume, and see the monthly cost.
  • Comparing models on price — the same prompt priced across GPT, Claude and Gemini often differs by an order of magnitude.
  • Fitting a document into the context window — check the usage bar before sending a long PDF extract or codebase dump.
  • Trimming system prompts — watch the token count drop live as you shorten boilerplate instructions.
  • Chunking for RAG — size embedding chunks in tokens rather than characters, which is what the model actually limits.

Frequently Asked Questions

How accurate is the offline estimate?

For English prose and typical source code it usually falls within about 10% of the exact count. Accuracy drops for unusual content such as long base64 blobs, dense emoji or mixed scripts. Switch to exact mode for OpenAI models when the precise figure matters, for example when you are close to a context limit.

Why can't Claude and Gemini be counted exactly?

Neither Anthropic nor Google ships a client-side tokenizer that a web page can run; both expose server-side counting endpoints that require an API key. Rather than ask you for a key, this tool applies a calibration factor per model family. Note that Anthropic states its Claude 4.7 and newer tokenizer produces roughly 30% more tokens for the same text than earlier Claude models, and that factor is built in.

Is my prompt uploaded anywhere?

No. Counting happens in JavaScript in your tab. The only network request the page can make is the optional tokenizer vocabulary download, which is a static file and carries none of your text.

Are the prices current?

Prices were checked on 31 July 2026. OpenAI and Anthropic figures come from their official pricing pages; Google figures come from public pricing summaries and are marked as unverified in the tool. Vendors change prices often, so confirm against the official page before committing to a budget.

Does the count include chat formatting overhead?

No. Chat APIs add a handful of tokens per message for role markers and separators, typically three to seven tokens per message plus a few for the reply priming. For a long prompt this is negligible; for many short messages, add roughly four tokens per message.

Related Tools