Tool
Claude Token Counter
This page estimates Claude tokens from your text. It is an estimate, not the number the API will bill. The sections below explain why, and how to use it safely.
Result
- ≈ 55 tokens (estimate)
193 characters · 28 words
Enter your model's current price. We never hard-code prices.
Why Claude cannot be counted exactly offline
To count tokens exactly you need the model's tokenizer: its vocabulary and merge rules. OpenAI publishes its encodings, so those can run anywhere. Anthropic does not publish a tokenizer that a browser can load for current Claude models. Any tool that claims an exact offline Claude count is either guessing or using a tokenizer for a different model.
The one exact route is the provider's own token counting endpoint, which takes your messages and returns the count the model will see. It needs an API key and a network call, so a page that keeps your text local cannot use it. If a limit matters, call that endpoint from your own backend.
How the estimate is made
The estimate divides the character count by a fixed characters-per-token ratio, 3.5, and rounds. For plain English prose that ratio is on the conservative side, so the figure leans high there. Code and non-English text usually tokenize into more tokens than the ratio implies, so real counts for them usually land above the estimate. It is a heuristic, applied the same way to every input.
Where the estimate drifts
A flat ratio is a good fit for plain English and a poor one for much else. Source code tends to tokenize into more tokens than its character count suggests, because of punctuation, operators and unusual identifiers. Text in languages other than English, especially those with non-Latin scripts, often takes noticeably more tokens per character. Emoji and other rare symbols can cost several tokens each. Long runs of digits and base64 strings are also expensive.
Going the other way, repetitive prose with very common words can come in under the estimate. So treat the figure as a midpoint with real spread on either side, and a wider spread for code and non-English text.
Budgeting with a margin
Decide what the number is for. For sizing, such as whether a corpus is tens of thousands or millions of tokens, the estimate is enough. For a hard limit, keep headroom: 15 to 20 percent for English prose, more for code-heavy or multilingual input. Then reserve room for the reply, because output shares the context window with the prompt.
If you are close to the edge even with a margin, stop estimating and count with the endpoint. A request that fails on length costs you more than the extra call.
A worked example
The example prompt above is a short instruction wrapped around a diff line. The instruction is plain English and estimates well. The diff line is the risky part: operators, a dotted path and the optional-chaining question mark tend to split into more tokens than the character count implies. If you paste a whole diff, expect the real count to land above the estimate, and size your margin to match.
Frequently asked questions
Is this count exact?
No. It is an estimate based on a characters-per-token ratio. Exact Claude counts require the provider's token counting endpoint.
Does my text leave the browser?
No. The estimate is computed locally from the length of your text. Nothing is sent to a server.
How wrong can the estimate be?
For plain English it is usually close. For code, non-English text, emoji and encoded data it can be off by a meaningful amount, generally low. Add a larger margin for those.
How do I get the exact number?
Send your messages to the provider's token counting endpoint from your own server using your API key. It returns the count the model will use for that request.
Related tools
- Token Counter
Count tokens for any text, exactly for OpenAI models and estimated for Claude, in your browser.
- OpenAI Token Counter
Exact o200k_base token counts for GPT-style prompts, computed locally.
- Agent Framework Picker
Five questions to decide between a plain loop, an SDK, or a framework.
- LLM Cost Calculator
Estimate what an LLM feature costs per request, per day and per month from your own token counts and prices.
- Agent Run Budget Simulator
See how an AI agent's cost grows turn by turn and where your budget cap would stop it.
- JSON to Zod
Paste a JSON sample or a JSON Schema and get a Zod schema and TypeScript types, in your browser.
- Tool Schema Validator
Check an OpenAI, Anthropic or MCP tool definition for common mistakes and convert it to the other two formats.