What This Calculator Measures
The AI Token & Cost Calculator turns a prompt (and optional completion) into two numbers that actually matter when you're building with an LLM API: how many tokens it uses, and what that costs in dollars, model by model.
How Tokens Work
Language models don't read text character-by-character or word-by-word — they break it into tokens, chunks of text produced by a byte-pair-encoding (BPE) algorithm trained on huge amounts of text. A token is often a whole short word, a word fragment, or a punctuation mark. As a rough rule of thumb, 1 token is about 4 characters or 0.75 words of English text, but this varies a lot by language and content type (code and non-English text often use more tokens per character).
Why Accuracy Differs by Provider
- OpenAI models (GPT-5.x, GPT-4.1, o-series) all use OpenAI's
o200k_baseBPE vocabulary. That vocabulary is public, so this calculator runs the exact same tokenizer algorithm entirely in your browser — no network call, no API key, and the count matches what OpenAI's own API would report. - Anthropic Claude and Google Gemini don't publish an offline tokenizer. The only way to get an exact count is to call the provider's own token-counting endpoint (Anthropic's
/v1/messages/count_tokens, Google'scountTokens). If you add your own API key in the calculator, we forward it to that endpoint for a single request (never stored) and show you the real number. Without a key, you'll see a clearly labeled estimate instead.
The Cost Formula
input cost = (input tokens / 1,000,000) × input price per million tokens
output cost = (output tokens / 1,000,000) × output price per million tokens
total cost = input cost + output cost
If a model supports prompt caching and you mark the input as a cache hit, the calculator swaps in the discounted cached-input rate instead of the standard input price.
Worked Example
Say your prompt tokenizes to 1,200 tokens and the model replies with 400 tokens, using a model priced at $2.50 input / $15.00 output per million tokens:
- Input cost: 1,200 / 1,000,000 × $2.50 = $0.003
- Output cost: 400 / 1,000,000 × $15.00 = $0.006
- Total: $0.009 per call
Multiply that by your expected calls per day to see your real daily spend.
Common Mistakes
- Forgetting output tokens can dominate cost. Output pricing is usually 4-6x higher than input pricing, so a short prompt with a long answer can cost more than a long prompt with a short answer.
- Assuming all providers tokenize the same way. The same sentence can produce different token counts on GPT vs. Claude vs. Gemini — always price with the actual model's count, not a generic estimate, when the difference matters to your budget.
- Ignoring system prompts and tool definitions. If you're using function calling or a long system prompt, those tokens count too and should be included in what you paste into the calculator.
Frequently Asked Questions
Frequently Asked Questions
Related Calculators
You might also find these tools helpful
