Token Counter
How it works
Which models this count applies to
o200k_base is the encoding used by GPT-4o, GPT-4o mini, the o-series reasoning models and their successors. Older GPT-4 and GPT-3.5 used cl100k_base, which segments differently — counts differ by roughly 5-15% between the two on typical English text. Anthropic (Claude) does not publish its tokenizer at all, so no browser tool can give an exact Claude count; the o200k number is a reasonable ballpark, and Anthropic's API reports exact usage after the fact. The counts here are for raw text — a chat API request adds a few tokens of message framing per message.
How byte-pair encoding works
The text is first split by a regex into pre-tokens — word-like chunks, number groups of at most three digits, punctuation runs, whitespace. Each pre-token becomes UTF-8 bytes, and adjacent pairs are repeatedly merged, always choosing the merge the vocabulary ranks cheapest, until nothing merges. That is why common English words are one token, why a long number becomes several 3-digit tokens, and why CJK and emoji cost more: 安 is 3 UTF-8 bytes and often 1-2 tokens, while a family emoji glued from four codepoints can cost 7 or more. The TOKENS mode makes all of this visible.
Exact, and still offline
This is not an estimate: it is the same vocabulary file OpenAI publishes for tiktoken (199,998 merges), with rank equal to line number, and the same pre-tokenizer pattern, verified token-for-token against the reference implementation across ASCII, CJK, emoji, RTL text and code. The vocabulary ships from this site as a JavaScript module — the page's Content-Security-Policy forbids every network request, so your text is never sent anywhere; even the vocabulary cannot be fetched from a third party.
Examples
| hello world | 2 tokens: "hello" + " world" |
| 1234567890 | 4 tokens: "123" "456" "789" "0" |
| 安静地清理一切,然后离开。 | 13 tokens for 13 characters |
FAQ
Is this count exact or an estimate?
Exact for o200k_base: full BPE with the published vocabulary, verified token-for-token against tiktoken's reference output. It is not a chars-divided-by-four heuristic.
Can it count Claude (Anthropic) tokens?
No tool in a browser can: Anthropic has never published its tokenizer. The o200k count is a usable ballpark for budgeting, and the Anthropic API returns exact input/output token usage with every response.
Why does the first count take a moment?
The 199,998-entry vocabulary (~2.5 MB compressed to less over the wire) is imported the first time you type, then cached by the browser like any script. Everything after that is instant and fully offline.
Why is my number split into 3-digit chunks?
The o200k pre-tokenizer caps digit runs at three (\p{N}{1,3}), so 1234567890 tokenizes as 123 · 456 · 789 · 0. This is deliberate model design — it keeps arithmetic-relevant digit groups short.
Does a chat request cost exactly what this shows?
The text itself, yes — plus a small fixed overhead the API adds per message for role framing (a few tokens each), and any tools/system scaffolding your request includes. Count each message's content here and add the framing.
Is my text uploaded to a server?
No. The page ships a strict Content-Security-Policy: connect-src 'none' blocks fetch, XHR, WebSockets and beacons, while default-src 'self' and form-action 'none' block every other way markup could send data off-site. Tokenization happens in your browser and cannot leave it.