Work out what an AI API will cost per request, per month and per year from token counts.
You supply current prices, so the result never goes stale.
How do you calculate LLM API costs?
Cost = (input tokens ÷ 1,000,000 × input price) + (output tokens ÷ 1,000,000 × output price), multiplied by your request volume. Output tokens usually cost several times more than input. Cached prompt prefixes bill at a much lower rate, and one token is roughly 0.75 English words.
Understanding your result
Output tokens typically cost several times more than input tokens, which flips the usual instinct about where to optimise: trimming a verbose system prompt saves less than instructing the model to answer concisely. Prompt caching changes the arithmetic again — when a large, stable prefix such as a system prompt or document context repeats across requests, the cached portion bills at a fraction of the normal input rate, and the saving grows directly with how often you repeat it. Token counts are also not words: budget roughly one token per 0.75 English words, and expect code, JSON and non-Latin scripts to consume noticeably more per character.
Formula and method
Cost per request = (uncached input ÷ 1,000,000 × input price) + (cached input ÷ 1,000,000 × cached price) + (output ÷ 1,000,000 × output price). Monthly cost is that figure multiplied by your request volume.
Assumptions and limitations
This is arithmetic on the numbers you supply, so its accuracy depends on yours. Published prices change frequently and vary by model, region and commitment tier, which is exactly why none are baked in. Token counts are approximate — roughly 0.75 words per token in English, and noticeably higher for code, JSON and non-Latin scripts — so measure real usage with your provider’s tokenizer before committing to a budget. Batch discounts, rate-limit tiers and image or audio pricing are not modelled.
Worked example
A request using 2,000 input and 600 output tokens, at 3 and 15 per million respectively, costs 0.006 for input plus 0.009 for output — 0.015 per request, or 150 a month at 10,000 requests.
How to use this tool
- Estimate the input and output tokens a typical request uses.
- Copy the current prices per million tokens from your provider.
- Add cached input tokens and the cached rate if you use prompt caching.
- Enter your monthly request volume to see the total.
Common mistakes to avoid
- Pricing per thousand tokens when providers quote per million.
- Assuming input and output cost the same rate.
- Estimating tokens from word count without checking a real tokenizer.
- Forgetting that conversation history re-sends earlier turns as input on every call.
About the LLM API Cost Calculator
The LLM API Cost Calculator turns token counts into money. Enter the input and output tokens a typical request uses, the current price per million tokens for each, and your expected monthly volume — it returns the cost per request, per month and per year, along with a scale table and the saving from prompt caching.
Who should use this tool
Developers and product teams budgeting for an AI feature, and anyone comparing model prices before committing.
Benefits
- No hardcoded prices — you enter current rates, so it never goes out of date.
- Separates input, output and cached-input costs, which are priced differently.
- Shows the monthly saving that prompt caching delivers.
- Scale table from 1,000 to 1,000,000 requests for capacity planning.
Practical use cases
- Budgeting an AI feature before you build it.
- Comparing two models by cost at your actual token usage.
- Working out whether prompt caching is worth implementing.
- Estimating unit economics per customer or per request.
Explore all Developer Tools tools
Frequently asked questions
How many tokens is a word?
Roughly one token per 0.75 English words, so about 1,300 tokens per 1,000 words. Code, JSON and non-Latin scripts run higher, so measure with your provider’s tokenizer for anything important.
Why are output tokens more expensive?
Generating text requires a forward pass per token, whereas input is processed in parallel. That difference in compute is reflected in the pricing, usually by a factor of three to five.
What is prompt caching?
When a long, unchanging prefix repeats across requests, the provider can reuse its processed form and bill those tokens at a much lower rate. It pays off best for large system prompts and document context.
Why does this not include model prices?
Because they change often. A hardcoded price list would quietly become wrong; entering the current figure yourself keeps the result correct indefinitely.
How do I reduce my API costs?
Ask for shorter outputs, cache stable prompt prefixes, trim conversation history you re-send each turn, and route easy requests to a smaller model.