LLM Token Counter
The LLM Token Counter measures how many tokens a piece of text will consume when sent to a large language model. Tokens are the unit models bill by and the unit their context windows are measured in, so counting them is the only way to predict cost and fit before you make an API call.
How to Use
- 1
Paste your prompt, document, or code snippet into the input box, or click Sample prompt to try an example.
- 2
Choose GPT-4o, GPT-4, or GPT-3.5 Turbo for exact counts, or Claude or Gemini for a labelled estimate.
- 3
Check the token count, character and word counts, and the context-window usage bar.
- 4
Adjust the price per 1M tokens to the vendor's current price and read the estimated cost for your text.
Frequently Asked Questions
What is a token?
How accurate are the GPT token counts here?
Why are the Claude and Gemini counts labelled estimates?
Why did my Claude token count jump by about 30%?
How many tokens is 1,000 words?
How do I reduce token usage?
What is a context window, and why does the usage bar matter?
How is the cost estimate calculated?
Is my prompt uploaded anywhere?
Why does code cost more tokens than prose?
Generative Answer & AI Documentation
What is the LLM Token Counter?
The LLM Token Counter measures how many tokens a piece of text will consume when sent to a large language model. Tokens are the unit models bill by and the unit their context windows are measured in, so counting them is the only way to predict cost and fit before you make an API call. This tool runs the exact OpenAI tokenizer in your browser for GPT models, and gives clearly-labelled heuristic estimates for Claude and Gemini, whose vendors publish no offline tokenizer.
Why use LLM Token Counter offline?
Prompts are often proprietary: system prompts encode product behaviour, pasted documents may be internal, and pasted code may be unreleased. A server-side counter would receive all of that text. This tool tokenizes locally — the tokenizer is JavaScript running in your tab — so your prompt never leaves your device. Offline counting is also instant and unlimited, with no account and no API key of your own to spend just to measure a prompt.
When should you use this tool?
Use it before sending any long prompt to an API, when a request fails with a context-length error, when you are trimming a system prompt to cut costs, and when you are comparing two prompt versions to see which is cheaper. It is also the right check before pasting a large document into a chat interface: if the document alone fills most of the context window, split it into chunks or summarize it first.
Key Benefits
- Exact GPT counts: the real o200k_base and cl100k_base tokenizers run in your browser — no guessing, no approximation for OpenAI models.
- Honest estimates: Claude and Gemini counts are labelled as estimates with the method shown, so you never mistake a heuristic for a bill.
- Cost before you spend: an editable price field turns tokens into dollars before the API call, not after the invoice.
- Context awareness: the usage bar shows how much of the model's window your text already occupies.
Common Use Cases
- Budgeting API spend for a prompt you send hundreds of times a day.
- Trimming a system prompt until it fits a smaller, cheaper model.
- Diagnosing context-length errors on long documents or code files.
- Comparing prompt versions by token cost before A/B testing them.
- Checking whether a pasted file will fit in a chat interface at all.
Developer Notes & Best Practices
Remember that the API counts more than your visible text: chat templates add special tokens around each message, and the model's reply consumes output tokens at a higher price. Budget with headroom — if your input is 90% of the window, the reply has almost nowhere to go. When comparing models, count the same text under each model's tokenizer rather than assuming counts transfer; o200k_base and cl100k_base disagree on code-heavy text. Re-check prices on the vendor's pricing page regularly: model prices have fallen repeatedly, and a stale price makes every estimate wrong.
- Use long, random passwords (16+ characters) for anything important, and a password manager to keep them.
- Check a generated code scans or validates before printing a batch of labels.
- Treat generated secrets like typed ones — store them securely and never commit them to a repo.
Common Mistakes
- Treating the Claude or Gemini estimate as exact — it is a heuristic, and the vendor's count is the only exact number.
- Counting only the user message and forgetting the system prompt, conversation history, and the reply itself.
- Using the 750-words-per-1,000-tokens rule on code, where the ratio is far worse.
- Budgeting with last year's price — verify the current per-1M price before any cost projection.
Limitations
GPT counts are exact for the raw text you paste when the tokenizer package loads — if it fails to load, the page warns you and falls back to a labelled approximation. The API adds chat-template tokens around messages, so a real request costs slightly more than the count shown. Claude and Gemini counts are heuristic estimates because those vendors publish no offline tokenizer. The cost estimate covers input tokens only at the price you enter — output tokens, cached-token discounts, and batch pricing are not modelled. Context-window sizes and prices change as vendors release new models, so verify both on the vendor's pages for production budgeting.
Structured Input/Output Example
Summarize the following quarterly report in three bullet points, focusing on revenue growth and risks.
Tokens: 19 (exact, o200k_base) Characters: 102 Words: 15 Cost: $0.000048 at $2.50 per 1M tokens Context used: 0.01% of 128,000 tokens
Related Tools
JSON Formatter
JSON formatter: turn minified or messy JSON into readable, indented output. 2 spaces, 4 spaces, or tabs — paste, click Format, copy or download.
JWT Decoder Offline
JWT decoder offline: inspect a token’s header, payload claims, and expiry as readable JSON. 100% client-side — production tokens never leave your browser.
Regex Tester
Regex tester: debug regular expressions with live match highlighting, match counts, and instant syntax feedback. Flags g, i, m, s supported.