
Count LLM Tokens and Estimate API Cost Locally (OpenAI, Claude, Gemini)
Before calling an LLM API: count tokens, estimate USD cost and check context-window fit — 100% in the browser without sending your prompt.
Counting tokens before you call an LLM API
Every request to OpenAI, Anthropic or Google is billed in input tokens and output tokens, not in words or characters. A long system prompt, few-shot examples or a multi-turn history use up context window budget before your user question. Without measuring first, you learn about an overflow from a 400 error and about the cost from the invoice at the end of the month. On FastMinify, the LLM token counter, the LLM pricing calculator and the context window calculator run entirely in your browser. Your text never leaves the device. The AI & LLM tools hub links the whole workflow.
Honest limits and best practices
FastMinify is for quick planning in the browser. It does not replace accounting reconciliation or runtime optimization.
Counting often reveals obvious padding in system prompts and duplicated context.
Unlike many online counters that upload text to a server, FastMinify tokenizes locally. Useful for prompts with proprietary code, PII or internal specs.
What tokens, tiktoken and heuristics actually measure
A token can be a whole word, a syllable, punctuation or a fragment. "Development" may span several tokens depending on the model; "API" is often one. That is why a word counter does not replace a token counter for LLM billing.
FastMinify loads js-tiktoken on demand for OpenAI models (o200k_base or cl100k_base encodings) and shows an Exact badge. For Claude and Gemini, Anthropic and Google do not publish browser tokenizers, so we apply a characters-per-token heuristic (±5–15% typical) and show an Estimate badge.
[{"role","content"}] array with ChatML overheadCost depends on both directions: the prompt, which is input, and the completion, which is output. The context window caps input plus reserved output. The context window calculator subtracts an output reserve, 15% by default, to estimate the effective input budget.
Counting, estimating and checking the window in three tools
Paste your prompt or a JSON messages array into the LLM token counter. The limit is 512 KiB of UTF-8. Turn on Compare all models to see the counts for every model in the table.
Transfer the input and output token counts into the LLM pricing calculator, or paste the prompt to derive input tokens through the same countTokensAsync pipeline. Rates come from a manually reviewed llm-models.json table, and its verification date is shown on the tool.
The context window calculator reuses the same counting pipeline and compares your prompt to the effective budget (window minus output reserve). Use it before multi-turn agents or large RAG pastes.
You assemble a system prompt, 20 vector chunks and a user question for GPT-4o.
Count the full context
Paste everything, or the messages array, into the token counter. Note the input tokens for the target model and check whether the badge says Exact or Estimate.
Check the headroom
Open the context window calculator with the same text. If the verdict is Near limit or Won't fit, trim chunks or switch to a model with a larger window.
Project monthly cost
In the pricing calculator, enter the input tokens and an estimate of the output tokens (for example 500). Fill in the cached input if the system prompt is stable, then enter the expected calls per day to get the monthly figure.
Conclusion
Counting tokens before the API call avoids truncation and billing surprises. Use the LLM token counter for a clear breakdown (Exact for OpenAI, Estimate elsewhere). Use the context window calculator to check RAG or multi-turn headroom, then the pricing calculator to project the USD cost. All of it runs in the browser, so your prompt never goes to a provider.
Count your tokens and estimate cost now
Related Articles

Paste a token and a JWKS to check an RS256, ES256 or HS256 signature in your browser. How kid picks the key, measured errors and the claims to check.

HTTP/2 and HTTP/3 change how files travel, not how big they are. Measured sizes, compile times and bundling tests show what minification still saves.

Convert a Unix epoch to a readable date and back, tell seconds from milliseconds, and avoid time zone, JWT and clock change traps, all in your browser.