Tokens: why models do not count in words
Take two sentences from this blog. The first is a shortened version of the opening line of Ask Claude Code to review how you work:
Every session you run through Claude Code is written to disk as JSON.
The second is the opening words of the Balochi post about getting the language into Google:
ھر دو، چار یا شَش ماه گوزیت ھمے میسج شنگ بیت
Thirteen words and eleven words. Run through the tokeniser OpenAI used for GPT-4, the English sentence becomes 14 tokens. The Balochi sentence becomes 41.
The shorter sentence costs nearly three times as much.
Every limit and every price on a language model API is quoted in that unit. Not words, not characters. If you plan a prompt, a budget or a product around word counts, you are measuring in the wrong unit, and the error depends on what language you write in.
What a token is
The tiktoken README (checked November 2026) puts it in one line: “Language models don’t see text like you and I, instead they see a sequence of numbers (known as tokens).”
A tokeniser is a fixed vocabulary of text fragments, each with an integer ID. Text goes in, a list of IDs comes out, and the model only ever sees the IDs. The two vocabularies used below have 100,277 entries (cl100k_base, GPT-4) and 200,019 entries (o200k_base, GPT-4o and GPT-5), according to tiktoken 0.14.0 itself. The model-to-vocabulary mapping is in tiktoken/model.py.
The vocabulary is not a dictionary. It is learned, usually with byte pair encoding. Sennrich, Haddow and Birch (ACL 2016, arXiv v5, June 2016) took BPE, an old compression trick, and used it to split words for machine translation. Start with single characters, find the pair that appears next to each other most often in the training text, merge it into a new symbol, and repeat until the vocabulary is the size you want. Common words end up as one token. Rare words get built from pieces. A word the model never saw in training can still be spelled out of smaller ones, which was the problem the paper set out to fix: translating rare and unseen words.
tiktoken runs BPE over raw bytes, not characters. The README lists what that buys: it is reversible and lossless, it “works on arbitrary text, even text that is not in the tokeniser’s training data”, and “on average, in practice, each token corresponds to about 4 bytes.”
That average is for the text the vocabulary was trained on. The rest of this post is about what happens away from it.
What the tokeniser actually does
Running tiktoken 0.14.0 with cl100k_base on a few short strings gave this:
'Hello world' 2 tokens ['Hello', ' world'] [9906, 1917]
' Hello world' 2 tokens [' Hello', ' world'] [22691, 1917]
'hello world' 2 tokens ['hello', ' world'] [15339, 1917]
'HELLO WORLD' 3 tokens ['HEL', 'LO', ' WORLD'] [51812, 1623, 51991]
'tokenisation' 2 tokens ['token', 'isation'] [5963, 8082]
'strawberry' 3 tokens ['str', 'aw', 'berry'] [496, 675, 15717]
'2026-11-24' 6 tokens ['202', '6', '-', '11', '-', '24']
'1234567890' 4 tokens ['123', '456', '789', '0']
Look at the first three lines. “Hello”, “ Hello“ and “hello” are three different IDs: 9906, 22691 and 15339. The space before a word belongs to the token, and so does the case. To the model these are three unrelated numbers that it learned, from training data, tend to mean the same thing.
Shouting costs extra. “HELLO WORLD” is not in the vocabulary as a pair of common words, so it comes out as three pieces.
“strawberry” arrives as str, aw, berry. Ten letters, three IDs. How many times the letter r appears is not written anywhere in the input the model receives. It has to have learned what is inside ID 15717.
The date is worse. 2026 splits into 202 and 6. A model reading that has never been handed the year as one thing.
Why the limits are in tokens
The model’s input is a list of IDs, so the only limit that can be enforced is a count of IDs. Anthropic’s context windows page (checked November 2026) is specific about what goes into that count: “the system prompt, every message in messages (including tool results, images, and documents), and your tool definitions.” The output counts too, including thinking.
The current numbers on that page: Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 have a 1M-token context window, and a single request can generate up to 128k output tokens. Go over on input and the API returns a 400 invalid_request_error, “prompt is too long”. Run out of room during generation on Claude 4.5 and newer models and the response stops with stop_reason: "model_context_window_exceeded".
A million tokens is not a million words. For the English sentence above it is close to one token per word. For the Balochi sentence it is closer to four.
Why the prices are in tokens
The pricing page (checked November 2026) lists Claude Opus 5.5 at $4 per million input tokens and $20 per million output tokens. Sonnet 5.5 is $2 and $10. The price per token is the same whatever language the token came from.
So the cost per word is not. In cl100k_base, the English sentence is 1.08 tokens per word (14 for 13). The Balochi sentence is 3.73 tokens per word (41 for 11). Same model, same rate card, about three and a half times the cost per word. The same context window also holds about three and a half times fewer Balochi words.
The reason is visible in the output. The first character of the Balochi sentence, ھ, is two bytes in UTF-8. cl100k_base has no token for it, so it falls back to the raw bytes and spends two IDs, 150 and 122, on half a character each. The byte fallback is what lets BPE handle “arbitrary text”. It is also what makes it expensive.
The newer vocabulary does better. o200k_base turns the same Balochi sentence into 21 tokens, with ھر as a single token, while the English sentence stays at 14. Twice the vocabulary, half the tokens, for this one language.
A token is not even a fixed unit
Anthropic changed its own tokeniser with Claude Opus 4.7. From the pricing page: “Claude 4.7 and later models and Claude Mythos Preview use a newer tokenizer”, which “produces approximately 30% more tokens for the same text.” The token counting page (checked November 2026) says it more bluntly: “don’t reuse token counts measured on the older model to estimate costs or context window fit”.
So a prompt that counted 10,000 tokens on Claude Sonnet 4.6 can count around 13,000 on Claude Opus 4.7 or later without a word of it changing.
Anthropic does not publish its tokeniser the way OpenAI publishes tiktoken. The way to count Claude tokens is the /v1/messages/count_tokens endpoint, which takes the same request body as a normal message and returns input_tokens. The docs’ own example, a system prompt of “You are a scientist” and a user message of “Hello, Claude”, returns { "input_tokens": 14 }. The endpoint is free, rate-limited (5,000 requests per minute on the Start tier), and the docs call the number an estimate that “might differ by a small amount” from the real request.
What was and was not run
The token counts in this post come from tiktoken 0.14.0, installed with pip inside a throwaway python:3.12-slim Docker container, using the cl100k_base and o200k_base vocabularies. That is OpenAI’s tokeniser, not Claude’s. No Claude token counts were run, because the counting endpoint needs an API key; every Claude number here is quoted from Anthropic’s docs.
Count your own
The test above takes a minute. Put this in an empty directory as tok.py:
import tiktoken
enc = tiktoken.get_encoding("o200k_base")
text = open("sample.txt", encoding="utf-8").read()
ids = enc.encode(text)
print(len(text.split()), "words,", len(ids), "tokens")
Then put a real sample of your text next to it as sample.txt and run:
docker run --rm -v "$PWD":/work -w /work python:3.12-slim \
sh -c "pip install -q tiktoken && python tok.py"
If your users write in anything other than English, use their text, not yours. Then, before you ship, send the same sample to count_tokens with the exact Claude model ID you plan to use. That number is the one you will be billed on.
Comments