DEV Community

Markee
Markee

Posted on Edited on

How to Estimate Your Monthly LLM API Bill (With a Worked Example)

A surprising number of API bills are still estimated as "a few million tokens times the price on the marketing page." That misses the two things that actually move the invoice: how many requests you send, and how much of the input is billed at a cheaper cache-read rate.

This post walks through a formula you can reuse, then runs one concrete workload against live list rates. The prices come from the public Ofox model catalog at https://api.ofox.ai/v1/models, fetched on 2026-11-26 15:03 UTC (2026-11-26 08:03 MST). They are catalog list rates, not a screenshot of each lab's official pricing page, and the two can differ. Confirm the official page before you set a budget.

The formula

For chat and completion models that charge per token:

monthly $ =
  (uncached_input_tokens / 1,000,000) * input_price_per_1M
+ (cached_input_tokens   / 1,000,000) * cache_read_price_per_1M
+ (output_tokens         / 1,000,000) * output_price_per_1M
Enter fullscreen mode Exit fullscreen mode

input_tokens and output_tokens are just requests per month times tokens per request. Cached input is input_tokens * cache_hit_share. If you do not use prompt caching, set that share to 0 and drop the middle term.

What this leaves out

These omissions matter. Most of them make the real bill higher than the estimate (batch pricing is the main exception that can make it lower):

  • Batch discounts, if the provider offers a cheaper batch endpoint.
  • Cache-write fees. Some APIs charge you to write a prompt into the cache, then a lower rate to read it. The formula only uses the read rate.
  • Tool-call charges, web search, or other per-call add-ons.
  • Long-context tier surcharges, when a prompt crosses a published length breakpoint.
  • Reasoning or thinking tokens. Several models bill those at the output price, so a short visible answer can cost more than its final token count suggests.

If your traffic is images, audio, or video, do not use this formula as-is.

A worked example: a coding agent

I'll use a workload that looks like a small coding agent, not a production log:

  • 150 requests per day over 30 days → 4,500 requests / month
  • 12,000 input tokens and 1,200 output tokens per request
  • 40% of input tokens billed at the catalog's prompt-cache read rate

That is 54 million input tokens and 5.4 million output tokens per month. Of the 54 million input tokens, 21.6 million are treated as cache reads and 32.4 million as regular input.

Here is the same workload across ten catalog models. Prices are USD per million tokens, from the fetch dated above.

Model (catalog id) Input Output Cache read Monthly $ If cache = 0%
Claude Haiku 5.5 (anthropic/claude-haiku-5.5) $0.10 $0.50 $0.01 $6.16 $8.10
GPT-6 Luna (openai/gpt-6-luna) $0.10 $0.50 $0.01 $6.16 $8.10
DeepSeek V4.1 Flash (deepseek/deepseek-v4.1-flash) $0.30 $1.20 $0.006 $16.33 $22.68
Gemini 2.5 Flash (google/gemini-2.5-flash) $0.30 $2.50 $0.03 $23.87 $29.70
Grok 4.3 (x-ai/grok-4.3) $1.25 $2.50 $0.20 $58.32 $81.00
Gemini 2.5 Pro (google/gemini-2.5-pro) $1.25 $10.00 $0.125 $97.20 $121.50
GPT-6.2 Sol (openai/gpt-6.2-sol) $2.00 $10.00 $0.10 $120.96 $162.00
Claude Sonnet 5.5 (anthropic/claude-sonnet-5.5) $2.00 $10.00 $0.20 $123.12 $162.00
GPT-5.4 (openai/gpt-5.4) $2.50 $15.00 $0.25 $167.40 $216.00
Claude Opus 5.5 (anthropic/claude-opus-5.5) $4.00 $20.00 $0.20 $241.92 $324.00

One row in detail, so the table is auditable. For GPT-5.4:

  • Uncached input: 32.4M × $2.50 / 1M = $81.00
  • Cached input: 21.6M × $0.25 / 1M = $5.40
  • Output: 5.4M × $15.00 / 1M = $81.00
  • Total: $167.40 / month

With no cache hits, input becomes 54M × $2.50 / 1M = $135.00, and the monthly total is $216.00. In this example, a 40% cache hit rate saves $48.60 on GPT-5.4 and $82.08 on Claude Opus 5.5. On the cheapest rows the absolute saving is small (about $1.94). Cache helps most when the input price is high and a stable prefix — system prompt, repo map, tool schema — is sent on every request.

How to get tokens you can trust

The formula is only as good as the counts you feed it. Log prompt_tokens and completion_tokens from a typical day, then multiply by 30. If you do not have logs yet, tokenize a representative prompt with the vendor's tokenizer; do not count English words and call them tokens. If the agent loops (plan, tool, retry), count every turn, not just the final answer. Hidden reasoning tokens belong in the output bucket unless the vendor documents otherwise. Re-run the estimate when the model or the pricing page changes.

A shortcut

I built a free browser calculator that applies this formula to a table of official list prices and shows the same workload across models: tokenhubs.dev. The live page currently marks those official-page rates as checked on 2026-11-25; the table in this article is from the Ofox catalog fetch dated 2026-11-26, so treat them as two snapshots. The on-site estimate uses the same exclusions listed above. Parameter tags (context length, max output, tool calling, reasoning, caching, image input) come from the same public catalog. The calculation stays in the browser.

If you want to call a model through an OpenAI-compatible endpoint, the calculator also shows curl, Python, and Node snippets and links to Ofox. Disclosure: I operate tokenhubs.dev and jxzne.com. The Ofox link is an affiliate link, and I may earn a commission if you sign up through it. You do not need that account to use the calculator or to reproduce the table above. An English setup guide is at jxzne.com/en/developers.html.

The useful habit is not the particular dollar figure. It is writing the workload down — tokens, volume, cache share — and running the same formula when the model list changes.

Top comments (0)