LLM Token Counter — Free Online Text Tool
LLM Token Counter — Count Tokens for GPT, Claude and Gemini
Paste a prompt, a document or a chat transcript, choose a model, and press Count Tokens (Ctrl+Enter or Cmd+Enter) to see its token count. Context limits and API prices are measured in tokens. Counting runs in your browser with a local tokenizer, and the text is never sent to a model or a server.
Which tokenizer each model uses
The page calls the encodingForModel function from the js-tiktoken library (version 1.0.21). The model menu maps each entry to one of the library's encodings:
| Model in the menu | Encoding used | Shown in the UI |
|---|---|---|
| GPT-4o, GPT-4o Mini | o200k_base | Count with no label |
| GPT-4, GPT-4 Turbo, GPT-3.5 Turbo | cl100k_base | Count with no label |
| Claude 3 Opus, Sonnet, Haiku | cl100k_base, the GPT-4 encoding | Labeled (estimate) |
| Gemini 1.5 Pro, Flash | cl100k_base, the GPT-4 encoding | Labeled (estimate) |
The Claude and Gemini figures are estimates. Their providers do not publish a tokenizer for this use, so the tool counts their text with the GPT-4 encoding. Use the provider's own token-counting API when you need the exact figure.
What the panel shows
After a count, the panel shows four values for the text in the box:
- Tokens, the count from the encoding above.
- Characters, the length of the text in JavaScript code units.
- Words, the number of runs separated by whitespace.
- An approximation line: the token count times 4 (characters) and times 0.75 (words). This is the tool's rule of thumb for English text, not a measurement.
Worked example
This is a user object from an API response, formatted with two-space indentation:
{
"id": 42,
"name": "Ada",
"roles": [
"admin",
"editor"
],
"active": true
}With GPT-4o the panel shows 37 tokens, 93 characters and 13 words. The approximation line reads about 148 characters or about 28 words.
The same object minified onto one line, {"id":42,"name":"Ada","roles":["admin","editor"],"active":true}, is 63 characters and 20 tokens with GPT-4o.
Gotchas
Indentation costs tokens. The indented version above uses 37 tokens and the minified version uses 20 for the same data. Minify JSON before you paste it into a prompt, with the JSON Minifier, when the structure does not need to stay readable.
The four-characters-per-token rule underestimates JSON. The indented object is 93 characters and 37 tokens, about 2.5 characters per token. The approximation line assumes 4, so it overstates the characters for code and JSON.
Some non-English text needs fewer tokens with the newer encoding. The Japanese phrase こんにちは世界 counts 2 tokens with GPT-4o (o200k_base) and 4 tokens with GPT-4 (cl100k_base). The same text can give different counts from one menu entry to another.
The count covers only the text box. System prompts, chat formatting, images and tool definitions are not in the box, so they are not counted. A chat request uses more tokens than the number shown.
Special tokens break the count. Text that contains a special token such as <|endoftext|> makes the GPT encodings throw an error. The page logs the error to the console and does not show a new count, so the previous number stays on screen.
FAQ
Are the Claude and Gemini counts exact?
No. They are labeled (estimate), because the tool counts them with the GPT-4 encoding. The provider's own counter is the reliable number.
Does the count include the system prompt?
Only if you paste it into the box. The tool counts exactly the text in the editor.
Why does GPT-4o give a different count from GPT-4 for the same text?
GPT-4o uses o200k_base and GPT-4 uses cl100k_base. Most English text gives the same count with both, but text in some scripts, such as Japanese, can differ.
Is my text sent anywhere?
No. The count runs in your browser, and the page makes no network request while it counts.
Related tools
- AI Prompt Generator, for building prompts from templates
- Prompt Formatter
- Word Counter and Character Counter
- JSON Minifier