How to estimate your LLM costs before you ship
How to estimate LLM costs before you ship: price per token, real inputs, retries and unplanned calls, and a test of the model you plan to run.
Updated
To estimate LLM costs before you ship, multiply the tokens each call sends and receives by the price for those tokens, then multiply by how many calls you expect per day. Repeat that for every task in the product, then add the retries, long inputs and traffic growth that a demo never shows.
Start with the per-call formula
Each call costs its input tokens times the input price, plus its output tokens times the output price. Prices are quoted per million tokens, so divide each token count by one million before you multiply. Here is the arithmetic with placeholder rates of $1 per million input tokens and $4 per million output tokens. Those are not any vendor’s prices.
A call with 3,000 input tokens and 500 output tokens costs $0.003 for the input plus $0.002 for the output, or $0.005 in total. At 2,000 calls a day that is $10 a day, or about $300 over a 30-day month. Keep token count, price and volume as separate inputs in a spreadsheet or a small script, so one changed number updates one line. The LLM cost calculator runs this arithmetic for your numbers. Work that can wait can often go through a batch interface, which Anthropic’s Batch API prices at half the real-time rate, so give that work its own line. The batch API versus real-time guide covers the trade.
Measure tokens from real inputs
Most estimates go wrong at the token count, not at the price. A prompt template looks short on paper, but the document pasted into it may be far longer than the example you tested with. Take a sample of real inputs from logs or a staging database, count their tokens with your provider’s counting tool, and look at the spread.
Averages hide the expensive cases. Suppose 90 percent of requests carry 1,000 input tokens and 10 percent carry 40,000. The long 10 percent then supply more than 80 percent of the input tokens, so an estimate built on the typical request would miss most of the bill. Check the high end of the distribution as well as the middle.
Output needs the same care. Set a maximum output length on every request, then measure typical replies. System prompts and few-shot examples count as input on every call, so a long instruction block is paid for again each time. If the model reasons before it answers, that reasoning is billed as output, as reasoning tokens explains.
Count the calls you did not plan
Retries multiply cost on a bad day. A call that times out and retries three times can reach the provider four times, and failed attempts may still be billed. A summarizer that calls the model once per paragraph of a 12-paragraph document, then once more to merge the results, makes 13 calls where a naive estimate assumed one. Check whether each feature calls the model once per row, once per user or once per page load, and count any fallback provider used during an outage. For a longer list, read the hidden costs in production LLM apps.
A price estimate only helps if the cheaper model still passes your task, so price an alternative only after it matches today’s model on the same checked inputs. Compare cost per document rather than cost per token, as cost per document explains, because a document is closer to the work a user receives. The full method is in how to build a test set.
Size capacity from measured throughput
Price per call is only half the estimate. Throughput decides how much serving capacity your volume needs. Measure requests and tokens per second on your own inputs at the concurrency you expect, since a model that looks fast on one request can slow under load. Size for the peak hour, not the daily average, and check LLM rate limits if your provider caps throughput.
Before you set a budget, go through this list:
- List every feature that calls a model, and the trigger that fires each call.
- Record input tokens at the median and at the 95th percentile, from real samples.
- Set an output cap on every request, and measure the typical output length.
- Add retries, fallback providers and agent loops as extra calls.
- Multiply the daily estimate by 30 for a monthly figure, and add a range for traffic growth.
- Score the model you plan to run on a test set split by source.
- Rerun the estimate whenever prompt length, traffic or the model changes.
Expect a trade-off. A larger model may cost more per call but need fewer retries. A smaller model may be cheaper per call but need its own test set and upkeep. Put both into the same estimate.
Run the free audit on your code
Before you ship, list every place your code reaches a model. Our free AI cost audit does that from the repository itself. It reads the code as text on your machine, makes no network calls while reading, uploads nothing and saves a PDF of AI calls, models, estimated cost and risks such as missing output limits, calls inside loops and missing fallback providers. The tool is open source under the MIT license, so you can read exactly what it does.
If you would rather go through the results with someone, book a free call. Bring the tasks you plan to ship, the volume you expect and the test set you would use to compare models, and we will work through the estimate with you.
Questions
How do I calculate the cost of one LLM API call?
Multiply the input tokens by the input price and the output tokens by the output price, then add the two results. Price lists quote a rate per million tokens, so the token count has to be scaled down by a million before you multiply.
How do I find out how many tokens a request uses?
Use your provider's token counting tool on a sample of real requests. Look at the largest requests as well as the average, because a few long inputs often drive most of the bill.
How much should I budget for retries and traffic growth?
Add the extra calls from retries, fallback providers and agent loops to your daily estimate before you set a budget. Then rerun the estimate whenever your traffic or prompt length changes.