LLM Token Counter

Count tokens and estimate API cost for GPT-5, GPT-4o, Claude, Gemini, and DeepSeek — with a live token visualizer. Exact OpenAI tokenization, 100% in your browser.

published

  • [FREE]
  • [NO_SIGNUP]
  • [NO_UPLOAD]

An LLM token counter tells you how many tokens a piece of text will use — and what that costs — before you send it to a model’s API. Tokens are the unit large language models read and bill by (roughly ¾ of a word each), so counting them is how you predict cost, avoid blowing past a context window, and compare models. This one runs the real OpenAI tokenizers in your browser, estimates Claude / Gemini / DeepSeek, and never uploads your text.

How to count tokens

  1. Pick a model. The dropdown is grouped by provider (OpenAI, Anthropic, Google, DeepSeek). Selecting a model sets the tokenizer used and pre-fills its input/output prices.
  2. Paste text. Token, character, word, line, and byte counts update live, along with an estimated cost.
  3. Price a full request. Edit the $/1M prices to match your rate, and enter the number of output tokens you expect so the cost includes the model’s response, not just your prompt.
  4. Inspect the split. The token visualizer colors each token so you can see why some text costs more tokens than its length suggests.

Exact vs. estimated counts

ProviderTokenizer usedAccuracy
OpenAI (GPT-5, GPT-4o, GPT-4.1, GPT-4 Turbo, GPT-3.5)o200k_base / cl100k_base (the model’s own)Exact
Anthropic (Claude Opus 4.8, Sonnet 5, Haiku 4.5, Fable 5)o200k_base scaled ×1.18Estimate (±~15–20%)
Google (Gemini 2.5 Pro / Flash)o200k_baseEstimate
DeepSeek (V3)o200k_baseEstimate

Only OpenAI publishes a tokenizer that can run client-side, so those counts are exact. For the others, an exact number is only available from the vendor’s own server-side count endpoint — which would mean uploading your text. This tool stays private, so it approximates instead and labels every estimate clearly.

Why token counts surprise people

  • A “short” string can be many tokens. URLs, hashes, base64, and UUIDs fragment into lots of tokens because they don’t match common word pieces.
  • Whitespace and newlines cost tokens. Pretty-printed JSON or heavily indented code carries token overhead that minified text does not.
  • Non-English text costs more. Languages outside the tokenizer’s training distribution use more tokens per character — sometimes 2–3×.
  • Emoji and rare Unicode often split into several tokens each.
  • Output is billed too. The response usually costs more per token than the input; price the expected output, not just the prompt.

Estimating cost quickly

Cost for one request is:

cost = input_tokens / 1e6 * input_price + output_tokens / 1e6 * output_price

Because input and output are priced differently (output is usually 4–5× the input rate), a chatty model that returns long answers can cost far more than the prompt suggests. Use the expected output tokens field to model the whole round-trip.

Privacy and how it works

The tokenizer is gpt-tokenizer, pure JavaScript with the BPE ranks bundled into the page — no WebAssembly, no network. Your text is tokenized locally and never leaves the tab. You can confirm this in DevTools → Network: after the page loads, typing produces zero requests carrying your input. The Copy share link button encodes only your model and pricing choices into the URL fragment (#…), which browsers never send to servers — your text is deliberately excluded.

Frequently asked questions

What is a token?

A token is the unit an LLM actually reads — usually a short chunk of a word, not a whole word or a single character. As a rough rule of thumb, 1 token ≈ 4 characters ≈ 0.75 words of English text, so 100 tokens is about 75 words. Punctuation, whitespace, code, and non-English text tokenize differently, which is why you should count rather than guess. Both the input you send and the output the model generates are billed per token.

Is the token count exact?

For OpenAI models (GPT-5, GPT-4o, GPT-4.1, GPT-4 Turbo, GPT-3.5) the count is exact — it runs the same BPE tokenizers OpenAI uses (o200k_base and cl100k_base) directly in your browser. For Claude, Gemini, and DeepSeek the count is a labeled estimate: those vendors do not publish an in-browser tokenizer, so we approximate with an OpenAI tokenizer and scale it. Expect the estimate to be within about 15–20% (more on code or non-English text). For an exact count on those models, use the vendor's own token-counting endpoint.

Why is the Claude count only an estimate?

Anthropic's exact token count is only available from its server-side /count_tokens API, which would mean uploading your text. This tool is private-by-default and never sends your text anywhere, so it approximates Claude with OpenAI's o200k tokenizer scaled up by ~18% (OpenAI tokenizers undercount Claude on typical prose). It is good for budgeting and comparison, not for exact billing reconciliation.

How is the cost estimate calculated?

Cost = (input tokens ÷ 1,000,000 × input price) + (output tokens ÷ 1,000,000 × output price). The input tokens come from your pasted text; the output tokens are whatever you type into the "expected output tokens" box (leave it at 0 to price input only). Prices are pre-filled per model as editable defaults — change them to match your actual contract or the latest published rate.

Are the prices current?

The per-model prices are editable defaults stamped with the month they were last set, shown in the tool. Model pricing changes often, so treat them as a starting point and confirm the current number on the provider's pricing page — or just type your own negotiated rate into the input/output price fields.

Does my text get sent to a server?

No. The tokenizer runs entirely in your browser as bundled JavaScript — there is no upload and no API call. Open DevTools → Network and you will see zero requests with your text after the page loads. The share link encodes only your model and pricing settings (never the text) into the URL fragment.

What does the token visualizer show?

It paints each token as a colored chip so you can see exactly where the tokenizer splits your text — useful for understanding why a short string can cost more tokens than you expect (e.g. a long URL, an emoji, or a rare word breaking into several tokens). For performance the visualizer renders the first 2,000 tokens; the count itself is never capped.

Will this fit in the model's context window?

The tool shows your token count as a percentage of the selected model's context window and flags when you go over. Remember the window has to hold the input, the output, and any system prompt or conversation history — so keep headroom rather than filling it to 100%.

Can I count tokens for a whole conversation or system prompt?

Yes — paste the full text (system prompt, prior turns, and the new message) into the box to see the combined input token count. Note that chat APIs add a few tokens of formatting per message on top of the raw content, so a multi-message request will be a little higher than the sum of its parts.