How to Estimate LLM API Costs: A Method With Worked Examples
TL;DR: A defensible LLM budget is requests × (input tokens × input price + output tokens × output price), adjusted for cache hits — measure the four numbers, then use official prices.
A defensible LLM budget comes from four numbers you can measure — requests, input tokens, output tokens and cache hit rate — multiplied by prices you can cite. This guide walks through the method and three worked examples using list prices checked on 2026-10-20.
Open the LLM Cost Calculator →All guides
The formula
cost per request = ( uncached_input × input_price
+ cached_input × cached_input_price
+ output × output_price ) / 1,000,000
monthly cost = cost per request × requests per day × days
Prices are in US dollars per million tokens. “Output” includes reasoning tokens on thinking models — Google, for example, labels Gemini’s output price “including thinking tokens”.
Step 1 — measure, do not guess
- Take 20–50 real requests. Count the whole input: system prompt, tool definitions, retrieved documents and chat history, not just the user’s message. The token counter gives a quick local count.
- Read output tokens from the API’s
usagefield after real calls. Output length varies far more than input. - Use averages for the budget and keep the 95th percentile in mind for long-context price tiers.
Step 2 — know the three prices
Every vendor in our table quotes an input price, an output price and a lower price for cached input. Cached-input discounts differ a lot: on Anthropic, a cache hit costs 10% of base input on most models, 5% on Claude Opus 5.5 and Sonnet 5.5, and 2.5% on Claude Fable 5.1; on OpenAI’s GPT-6.1 Sol it is 5% and on GPT-6 Luna 10%; Qwen’s implicit cache bills hits at 20% for most models.
Writing to the cache can cost more than normal input: Anthropic charges 1.25× base input for a 5-minute cache write and 2× for a 1-hour write; OpenAI’s GPT-6 pages list cache writes at 1.25×; Qwen’s explicit cache creation is billed at 125%. For a steady workload the hits dominate, which is why the calculator models hits only.
Example 1 — a support chatbot
2,000 requests a day, 1,500 input and 400 output tokens on average, no caching, 30 days. Using the list prices:
| Model | Per request | Per month |
|---|---|---|
| gpt-6-luna | $0.00035 | $21.00 |
| Claude Haiku 5.5 | $0.00035 | $21.00 |
| qwen3.8-flash | $0.00041 | $24.78 |
| deepseek-flash (peak) | $0.00093 | $55.80 |
| gemini-3.5-flash-lite | $0.00145 | $87.00 |
Two lessons. First, small models are cheap enough that engineering time, not tokens, is the real cost here. Second, identical list prices do not mean identical bills: Anthropic says Claude 4.7+ models produce about 30% more tokens for the same text, so if your averages came from an OpenAI tokenizer, Claude Haiku 5.5 lands nearer $27 a month. With a 50% cache hit rate, gpt-6-luna and Claude Haiku 5.5 drop to about $16.95.
Example 2 — a coding agent with prompt caching
Agents re-send a large, stable prefix (instructions, tool schemas, open files) on every step. Assume 300 requests a day, 60,000 input and 3,000 output tokens each, 30 days:
| Model | No cache / month | 80% cached / month |
|---|---|---|
| deepseek-v4-pro (peak) | — | $268.49 |
| Claude Sonnet 5.5 | $1,350.00 | $529.20 |
| gpt-6.1-sol | $1,350.00 | $529.20 |
| gemini-4-argon (to 30 Nov 2026) | $1,350.00 | $529.20 |
| gemini-4-argon (from 1 Dec 2026) | — | $1,058.40 |
| Claude Opus 5.5 | — | $1,058.40 |
Caching cuts this workload by about 60%, which matters more than which mid-tier model you choose. Note the scheduled change: Google lists Gemini 4 Argon at $2 / $10 through 30 November 2026 and $4 / $20 from 1 December, so the same workload doubles in cost.
Example 3 — crossing a long-context threshold
One request with 250,000 input and 2,000 output tokens on gpt-6.1-sol costs $0.52. Push the prompt to 300,000 tokens and it crosses OpenAI’s 272K threshold: input is billed at 2× and output at 1.5× for the whole request, so it costs $1.23 — more than double for 20% more input. Keep an eye on your largest prompts, not just the average.
Choosing a model on cost
The examples show a pattern worth remembering: across the full price table, the spread between the cheapest and most expensive model for the same workload is often ten times or more, while the spread between two models in the same tier is small and is usually decided by tokenizer differences and cache pricing. So pick the tier first — can a small model do the job? — by testing quality on your own prompts, and only then compare vendors inside that tier. A model that is twice the price but needs half as many retries or shorter prompts can still be the cheaper choice.
Step 3 — add what the formula misses
- Conversation growth. Multi-turn chats re-send history, so average input grows with conversation length. Measure it on real sessions.
- Retries and failures are billed too. Add a margin (10–20% is a common planning buffer; adjust to your error rate).
- Batch discounts. Anthropic, OpenAI and Google list batch processing at 50% of standard rates for the models above; DeepSeek has off-peak hours at half price.
- Tools billed per call — web search, file search and similar features are priced separately from tokens on most platforms.
Step 4 — check the estimate against reality
An estimate is a hypothesis. After the first week in production, add up the usage fields your application logged (input, cached input and output tokens are reported separately by the vendors above) and compare them with the plan. The two numbers that drift most often are output length and cache hit rate: prompts that change at the start — a timestamp or user name in the system prompt — quietly break caching, because caches match on the prompt prefix.
Re-run the numbers whenever a vendor announces a price change or you switch models; the calculator’s price table carries the date it was last checked.
Put your own numbers into the LLM cost calculator: it uses the same price table as this guide, applies cache-hit prices and long-prompt tiers, and sorts every model from cheapest to most expensive.
Sources
Vendor features and prices were checked against these official pages on 2026-10-20. Products change; if something here no longer matches, the official page is right.
- OpenAI — API pricing
https://developers.openai.com/api/docs/pricing - OpenAI — GPT-6.1 Sol model page (long-prompt and cache pricing)
https://developers.openai.com/api/docs/models/gpt-6.1-sol - Anthropic — Pricing
https://docs.anthropic.com/en/docs/about-claude/pricing - Google — Gemini API pricing
https://ai.google.dev/gemini-api/docs/pricing - DeepSeek — Models & pricing
https://api-docs.deepseek.com/quick_start/pricing - Alibaba Cloud Model Studio — Model pricing
https://www.alibabacloud.com/help/en/model-studio/model-pricing - Alibaba Cloud Model Studio — Context Cache
https://www.alibabacloud.com/help/en/model-studio/context-cache