How to Estimate LLM API Costs

Estimate monthly LLM spend from users, prompts and token counts, and compare API pricing with a self-hosted GPU, with a worked example.

Last updated 2026-11-26

Language model APIs bill by tokens, not by request. A token is a small piece of text, roughly three quarters of an English word on average. Every prompt you send is billed on the tokens it contains, and every response is billed on the tokens it generates. To estimate a monthly bill, you need to turn your traffic into token volumes and multiply each by its price.

The formulas

monthly prompts  = daily users x prompts per user per day x 30
input tokens (M) = monthly prompts x input tokens per prompt / 1,000,000
output tokens (M) = monthly prompts x output tokens per prompt / 1,000,000
cache factor     = 1 - (cache hit rate x 0.5)
API cost         = input M x input price x cache factor + output M x output price
self-hosted cost = GPU nodes x node price, where GPU nodes = max(1, ceil((input M + output M) / capacity per node))

The cache factor applies a discount to the share of input tokens served from the provider's prompt cache. The 50% discount in the calculator matches the cached-input discount that OpenAI publishes for gpt-4o-mini. Other providers set different discounts, so check yours.

Rates and what they mean

  • Mini model: gpt-4o-mini lists at $0.15 per million input tokens and $0.60 per million output tokens, as reported by third-party pricing summaries. This is the rate the calculator uses for its mini option.
  • Frontier model: the calculator uses $2.50 and $10 per million tokens, which is the 2024 list price for gpt-4o. Newer flagship models have different prices, so replace this with the current figure before you budget.
  • Self-hosted GPU: the $580 node price and the 1,200 million tokens a month per node are planning assumptions. They exclude staff time, redundancy and idle capacity.

A worked example

A product has 2,500 daily users, each sending 6 prompts a day, with 1,200 input tokens and 450 output tokens per prompt. The cache hit rate is 30%.

  1. Monthly prompts: 2,500 × 6 × 30 = 450,000
  2. Input tokens: 450,000 × 1,200 = 540 million
  3. Output tokens: 450,000 × 450 = 202.5 million
  4. Cache factor: 1 − 0.30 × 0.5 = 0.85
  5. Mini model: 540 × $0.15 × 0.85 + 202.5 × $0.60 = $190.35
  6. Frontier model: 540 × $2.50 × 0.85 + 202.5 × $10 = $3,172.50
  7. Self-hosted: 1 node × $580 = $580

At this volume the mini model is cheapest. The self-hosted node looks cheaper than the frontier model, but it still needs someone to run it, and that cost is not in the figure.

Common mistakes

  • Estimating tokens from words. Use the provider's token counter on a real prompt. Code, non-English text and JSON use more tokens per word.
  • Forgetting output tokens. Output is billed at a higher rate, so long answers can dominate the bill.
  • Using an old price list. Prices change often. Check the provider's pricing page the day you budget.
  • Comparing API and self-hosting without labour. Self-hosting only wins when volume is high and steady, and someone maintains the system.

What to do next

Measure real token counts from your logs for a week, then run the calculator with those averages. Test the output length first, because shortening responses is often the cheapest way to reduce cost.