DEV Community

NextUsefulThing
NextUsefulThing

Posted on

Estimate AI API costs before you ship a feature

If you are adding a model call to an app, the dangerous part is not the first request. It is the bill after a hundred requests a day have been running for a month.

I got tired of doing that math in a spreadsheet, and of "free" cost tools that want an account before they show a number. So I built a small calculator that runs in the browser, uses official list prices, and does not send your token counts anywhere. This post is the method behind it, so you can do the same estimate even if you never open my page.

The only inputs that matter at first

For a standard chat or completion feature, a planning estimate needs five numbers:

  1. Input tokens per request (the prompt, system text, and any context you send).
  2. Output tokens per request (the model's reply).
  3. Requests per day.
  4. The share of input tokens you expect to be billed at a cached-input rate, if the vendor publishes one.
  5. The model's input, cached-input, and output prices, usually listed per 1 million tokens.

Everything else — reasoning tokens, long-context surcharges, tool calls, image or audio tokens, priority tiers, tax — will make the real invoice higher. Start with the five numbers, then add a margin for the extras you actually use.

A simple formula

For one request:

  • Uncached input tokens × input price, plus
  • Cached input tokens × cached-input price, plus
  • Output tokens × output price,

all using prices per 1 million tokens.

If a vendor does not publish a cached-input rate, bill that "cached" share at the ordinary input rate. That is conservative, not optimistic.

A planning month is 30 days, with no weekend discount unless the vendor says otherwise. (DeepSeek publishes off-peak rates that are half of its peak prices; if you use those, read the official hours before you assume the lower number.)

To turn English prose into a first token guess, a rough average is about 0.75 words per token, or four tokens for every three words. Tokenizers differ by model and language. Use this only to get started, then measure real usage.

A worked walk-through (no invented bill)

Suppose each request sends about 1,200 input tokens and gets about 400 output tokens. You expect 100 requests a day. You think half of the input will hit a prompt cache.

You would then:

  1. Split the 1,200 input tokens into 600 uncached and 600 cached.
  2. Look up the current official input, cached-input, and output prices for the model you want.
  3. Run the formula for one request, multiply by 100 for the day, then by 30 for the month.
  4. Repeat for one cheaper model and one stronger model, with the same token and request settings, and compare the three monthly figures.

I am not going to print a dollar total here. List prices move, and some introductory rates expire on a fixed date. As of a November 2026 check against official pages, for example, some Gemini introductory rates were scheduled to change on 1 December 2026 and 1 January 2027. Confirm the live pricing page before you set a budget.

What usually makes the real bill higher

The estimate above uses standard short-context list rates. It will be short if you also pay for:

  • Reasoning or "thinking" tokens
  • Long-context surcharges
  • Tool calls
  • Image or audio inputs
  • Priority processing or a regional endpoint
  • Tax

It will be high if you later get a batch discount or a committed-use deal. Treat the first number as a planning figure, not an invoice.

The browser calculator I use

I put this method into a page that already has official short-context list prices, last checked in November 2026, for flagship and smaller models from OpenAI, Anthropic, Google Gemini, xAI, Mistral, and DeepSeek. You enter tokens, daily requests, and a cache share. It returns a per-request, per-day, and 30-day estimate, plus a comparison table sorted by monthly cost.

The math runs in your browser. The page does not call a model API, and it does not upload your token counts. All list prices live in one JavaScript object on the page, so a rate change is a table edit, not a new backend.

You can try it here, with no sign-up: https://nextusefulthing.com/ai-api-cost-calculator/

If you would rather not use my page, the method above is enough. Keep a dated copy of the official prices you used, and refresh them when a vendor announces a change.

A closing rule

Estimate first, then verify. A calculator is general information, not a quote. If the feature matters, measure real token use in staging for a day and rerun the numbers before you promise a cost to anyone else.

Top comments (0)