LLM Token Counter
Count the tokens in a text for OpenAI models and see how it is split, with an estimate for other models, right in your browser.
Enter some text to count its tokens.
What a token is and how this counter works
A token is the unit of text a language model works with: a whole word, a fragment of a word, a punctuation mark or a space. Models don't read letters or words but sequences of tokens, and everything about them is measured in tokens: the maximum length of a conversation (the context window), how fast they answer and, with paid APIs, the cost. This tool counts the tokens in a text and shows you how it is split, right in your browser.
The count is exact for OpenAI models. The o200k_base tokenizer is the one used by GPT-5, GPT-4.1, GPT-4o and the "o" series models; cl100k_base is the one used by GPT-4 and GPT-3.5. These tokenizers' vocabularies are public, so the calculation runs entirely on your device and no text is sent to a server. The vocabulary is a few megabytes and is only downloaded when you enter your first text, not when you open the page.
For Claude, Gemini, Llama and other models an exact count isn't possible here, because each uses a different tokenizer that isn't always public. For those the tool shows an estimate using the rule of thumb of about four characters per token, which holds for English: for other languages, tokens are usually more. If you need the precise number, for billing for example, use the provider's official tool.
The colored breakdown shows how the text is cut: common words stay whole, long or rare ones are split, and a leading space is part of the token that follows. An emoji or an accented letter can take more than one token: in the view you see it whole, while the count stays exact. Trying the same text with the two tokenizers also shows how much the numbers change: the Italian sentence "Perché la stessa domanda a un assistente IA ottiene risposte diverse?" is 19 tokens with cl100k_base and 16 with o200k_base.
The cost is calculated by multiplying tokens by the price per million tokens. Prices change often and vary by model, for input and for output, so they aren't built into the tool: enter the price you read in the provider's price list and you get the text's cost. To go deeper into how text becomes tokens and why it matters, there's the guide "What is a token in an LLM" and the book "LLMs Unpacked", which devotes a chapter to this step.
Frequently asked questions
- Is the token count exact?
- Yes for the listed OpenAI tokenizers (o200k_base and cl100k_base), because their vocabulary is public and the calculation matches the models'. For Claude, Gemini, Llama and others the tool only shows a rough estimate, labeled as such.
- Why doesn't it count Claude's tokens?
- Claude's tokenizer isn't available for local use: it can only be queried through the provider's API, with a key and by sending the text to a server. To keep everything in your browser, the tool offers an estimate for Claude. For the exact number use Anthropic's official count.
- Why does the same text give different numbers with two tokenizers?
- Each tokenizer has a different vocabulary and so cuts the text differently. Newer models use larger vocabularies, which in many languages other than English can need fewer tokens. On the Italian sentence "Perché la stessa domanda a un assistente IA ottiene risposte diverse?" the count drops from 19 (cl100k_base) to 16 (o200k_base).
- How is the cost of a text calculated?
- By multiplying the tokens by the price per million tokens and dividing by a million. Enter the price from the provider's price list: prices change often and differ between input and output, so they aren't built into the tool.
- What happens with special strings like <|endoftext|>?
- They're treated as normal text and counted as such, with no error. In real models those markers have a special role, but for measuring the length of pasted text this is the most useful behavior.
- Is the text I enter sent to a server?
- No. Counting happens entirely in your browser. Only the tokenizer's vocabulary is downloaded from the site, the first time you enter text; your text never leaves your device.
From the books
