What is a token, and why does AI charge by the token?
Tokens are the pieces of text a language model reads and writes. How text is cut into them, why languages need different numbers, and why output costs more.
3 min readPart 3 of 21
On this page
AI services price by the token, limit conversations by the token and measure speed in tokens per second. A token is neither a letter nor a word. It's a piece of text: a whole word, part of a word, a punctuation mark or a single character, and spaces count too.
For English, OpenAI's rule of thumb is that one token is about 4 characters or three-quarters of a word, so 100 tokens are about 75 words. It's an estimate, and it doesn't carry over to other languages.
How text is cut up
Models don't cut at word boundaries. Most use a method called byte pair encoding, or BPE: start from the smallest pieces, then repeatedly merge whichever two neighbors appear together most often in a large body of text. The idea was brought to language models in a 2015 paper, whose example used four words:
Start from single letters
l o w l o w e r n e w e s t w i d e s tMerge the most common pair: e + s
l o w l o w e r n e w es t w i d es t
Then es + t
l o w l o w e r n e w est w i d est
Then l + o, and lo + w
low low e r n e w est w i d est
The pieces that survive become the model's vocabulary. Common words end up as one token, and rare words as several. "est" is now a piece of its own, so the model can recognize it in a word it has never seen.
Two consequences surprise people:
- Spaces and capitals matter. "red", "Red" and " red" with a leading space are different text, and an encoding may represent them differently.
- The model doesn't see letters. If a word arrives as one or two tokens, its spelling isn't in front of the model. That's why counting the letters in a word is oddly hard for models that write fluent essays.
Vocabularies differ between models. Llama 3's has 128,000 tokens, 100,000 of them from OpenAI's tiktoken and 28,000 added to handle languages other than English better.
Why languages aren't equal
If the text used to build the vocabulary is mostly English, English gets long, efficient pieces and other languages are cut finer. When OpenAI released GPT-4o in May 2024 with a larger vocabulary, it published how many tokens the same sentence took before and after:
With the older vocabulary, the same sentence took 34 tokens in Chinese against 27 in English, and 159 in Telugu. With the newer one, Chinese and English are level at 24. That's one sentence, so don't read it as an exact ratio, but the direction is clear: the gap comes from the vocabulary, and it can be closed.
A 2023 study that compared translations of the same text across many tokenizers found differences of up to 15 times between languages, even for tokenizers built to be multilingual. Where you pay by the token, that's a price difference for the same content.
Why you pay by the token
The work a model does grows with the number of tokens: it has to read every token you send and run a full calculation for every token it writes. Output almost always costs more than input, because the input can be processed together while the output has to be produced one token after another:
Three things make a bill larger than the text on screen suggests:
- The whole conversation is sent again with each message, because the model has no memory between calls. A long chat costs more per message than a short one.
- Hidden reasoning is output too. With reasoning models, tokens spent thinking are billed as output even though they aren't shown as part of the answer.
- More than your message is counted: instructions, tool descriptions, images and the markers between messages all take tokens.
In subscription apps such as ChatGPT Plus or Claude Pro you don't pay per token, but usage limits follow the same logic, so long chats use them up faster.
Counting tokens yourself
OpenAI has a web tokenizer that shows where text is cut. For Claude, Anthropic's API has a token counting endpoint. Counts differ between models, so count with the one you're going to use.