Token Counter for Local Models
Estimate how many tokens a prompt will use before you paste it into a local model. The count is calculated in your browser. It is not the official tokenizer for Llama, Mistral, Phi, or Qwen, and it can be off by roughly 10 to 15 percent. Use it to see whether a prompt is short, comfortable, or about to crowd the context window — not as a billing figure.
How the estimate is made
The page counts characters and divides by a factor that depends on the model family you pick. English prose is often near four characters per token on Llama-style BPE tokenizers. Code, JSON, and text in other scripts can be denser or sparser, which is why the result is labeled an estimate. The tool also shows character and word counts so you can sanity-check the number: a 400-word English paragraph is often in the 500 to 700 token range, not 4,000.
Phi-style tokenizers are often a bit more compact on English, so that option uses a slightly smaller divisor and the estimate comes out a little higher. Qwen is close enough to the Llama factor for a planning estimate. If you need an exact count, use the tokenizer in your runner or the model’s own tools. This page will not match that number every time.
How to use the number
- Paste the prompt and the document you plan to attach as text.
- Pick the closest model family. If you are unsure, use Llama / Mistral.
- Compare the estimate with the context you actually run: 4k, 8k, 16k, or whatever the model card says for your quant.
- Leave room for the answer. If the prompt is already 70 percent of the window, the model will cut the answer or drop the beginning of the prompt.
A practical buffer: keep the prompt under half of the context if you want a long answer, and under three quarters if you only want a short extraction. The estimate is not a promise that the runner uses the same window. Some apps reserve tokens for a system prompt you cannot see. If replies stop early, shorten the source, not just the instructions.
Worked examples
- A 120-word email prompt with no attachment is usually a few hundred tokens. Window size is not your problem. Format and temperature are. See How to Get Consistent Results.
- A 3,000-word article plus a summarize instruction can land around 4,000 tokens. That fits an 8k window with room for a short summary, and it is tight on a 4k window.
- A whole code file pasted “for context” often blows the budget before the question. Paste the function, not the repository.
What this tool will not do
- It does not load the model’s vocab file, so it cannot count special tokens or an invisible system prompt.
- It does not support a perfect count for every language. Chinese, Japanese, and Korean often use fewer characters per token than the English factor assumes, so the estimate can run low. If the text is mostly not English, treat the number as a floor and leave extra room.
- It does not send your text anywhere. Counting happens in the page.
Questions
Why doesn’t this match the token number in LM Studio or Ollama?
Those apps use the model’s tokenizer. This page uses a character divisor. Being within about 15 percent is expected. If you are within a few hundred tokens of the limit, trust the runner, not this estimate.
Which family should I pick for Gemma or GPT-style local models?
Use the generic or Llama estimate. The difference is smaller than the error bar of this method.
Should I count the answer too?
This box only counts what you paste. Add the answer length yourself. Five bullets are cheap. “Write 2,000 words” is not.
Can a shorter token count fix a bad answer?
Only if the failure was a full window. If the format is wrong on a short prompt, rewrite the prompt. Start with How to Write Better Prompts for Local AI Models.