How to Calculate the True Cost of LLM APIs and Control Your Budget After Price Increases
Several LLM providers have recently raised API prices, introducing steeper base rates for core models and premium tiers for complex tasks. This article explains how to model true API costs using a full pricing formula (input, output, cache write, cache read), account for rate limits and retry overhead, split workloads between primary and exploratory models, validate candidates with small-sample testing, and use a structured checklist for model selection.
Recently, some LLM providers have raised their API prices, with significant increases in base rates for core models, and some vendors have introduced premium tiers aimed at complex tasks. For teams that have already integrated LLMs into production systems, token consumption has become a fixed expense that requires long-term budgeting. After a price increase, teams need to re-evaluate which features genuinely deserve an LLM call and which can be moved to lower-cost alternatives.
This article does not evaluate any specific brand. It focuses only on selection methodology, cost modeling, and architecture design.
1. Cost Modeling and Cache Write Accounting
The list price is only part of the bill. Most providers charge separately for input, output, cache writes, and cache reads, so the cost of the same request can vary significantly depending on cache hit rates. Total cost can be estimated with the following formula:
Total cost = uncached input tokens × input rate + cache write tokens × cache write rate + cache read tokens × cache read rate + output tokens × output rate
All rates should be taken from the provider’s official pricing page. Billing details must also be verified item by item: whether pricing is tiered by context length, whether cache writes are billed separately, what triggers a write, how long the cache lives, and whether tool calls and retried requests count toward token usage. These rules are not standardized across providers, so a fixed ratio estimate will not work.
Here is a hypothetical example to illustrate the calculation. Assume an application processes 10 million input tokens and 2 million output tokens per day. Let the uncached input rate be p, the cache write rate be 1.25p, the cache read rate be 0.1p, and the output rate be 4p. These ratios are for demonstration only and do not represent any provider’s actual pricing. The hit rate is defined as the share of cache read tokens in total input tokens.
- At a 60% hit rate: cache reads are 6M tokens, and 4M tokens miss the cache. Of the misses, 2M are written to cache and the other 2M are ordinary uncached input. Input-side cost: 2M×p + 2M×1.25p + 6M×0.1p = 5.1Mp. Output-side cost is 8Mp, for a total of 13.1Mp.
- At a 20% hit rate: cache reads are 2M tokens, and 8M tokens miss. Again assuming 2M are written to cache and the remaining 6M are ordinary uncached input. Input-side cost: 6M×p + 2M×1.25p + 2M×0.1p = 8.7Mp. Total cost is 16.7Mp.
Between the two scenarios, input-side cost differs by roughly 71% (8.7Mp is about 71% higher than 5.1Mp). Total cost differs by only about 27%, because output cost is unchanged and represents a large share of the bill. When comparing options, you must look at both the input and output sides, not just the numbers on the pricing page.
For reliable results, first measure the real hit rate from billing data or gateway logs, calculated per day or per feature. Hit rates are easily affected by whether prompt prefixes are stable, whether the cache expires, and request concurrency, so they should not be treated as constants. A recommended practice is to aggregate the bill’s input, output, cache write, cache read, long-context, tool-call, and retry fields daily, then plug the actual rates back into the formula above.
2. Concurrency, Rate Limits, and Retry Costs
RPM (requests per minute), QPS (queries per second), and TPM (tokens per minute) determine a system’s real throughput. Lower-priced tiers usually impose tighter caps on all three. Once requests exceed the cap, they get queued, rejected, or retried — all of which add latency and cost.
Evaluations should compare peak load against the caps rather than daily averages. You can work through the following steps:
- Measure daily request volume and average tokens per request. Suppose there are 20,000 requests per day averaging 3,000 tokens (input plus output) each. That is 60M tokens per day, or roughly 42K TPM.
- Determine the peak factor. If peak-minute load is 4× the daily average, the peak is about 167K TPM. The peak factor should come from minute-level log data, using the P95 minute rather than the absolute maximum.
- Compare against the tier cap. If the TPM cap is 100K, the excess share is (167K − 100K) ÷ 167K, meaning roughly 40% of requests will be queued or retried.
- Account for retry costs. For requests rejected with a 429 status, confirm whether the provider bills for them. If it does, retry cost is roughly the number of failed requests multiplied by the per-request cost. Even if they are not billed, the waiting time introduced by exponential backoff degrades user experience and should be translated into a business cost.
If peak load persistently exceeds the cap, prioritize upgrading the tier, moving non-real-time tasks to off-peak hours, or routing part of the traffic to other models.
3. Splitting Work Between Primary and Exploratory Models
The primary model handles the core production path and must deliver stable output quality with controlled latency. The exploratory model is cheaper or faster and suits lower-risk tasks such as classification, information extraction, text rewriting, and draft generation. The division of labor should be written as explicit routing rules, not left to manual judgment.
The table below lists what to record when comparing the two model types.
| Comparison Item | Primary Model | Exploratory Model |
|---|---|---|
| Unit price | Per-request cost computed from real bills | Per-request cost computed the same way |
| Cache hit rate | Actual daily measured value | Actual daily measured value |
| Latency | P95 latency | P95 latency |
| Quality sampling | Sampled pass rate | Sampled pass rate |
| Suitable tasks | User-facing critical answers, complex reasoning | Classification, extraction, rewriting, drafts |
| Fallback strategy | Queue or switch to a backup model when throttled | Escalate to the primary model on timeout or quality failure |
Routing rules can be designed along three dimensions. First, by task type: simple tasks go to the exploratory model first. Second, by result quality: if the exploratory model’s output fails validation — for example, malformed format or low confidence — it is automatically escalated to the primary model. Third, by load: if the exploratory model is throttled or times out, traffic switches to the primary model or returns a cached result.
The share of traffic sent to the exploratory model should not be scaled up immediately. Start with a small rollout, such as 10–20% of comparable requests, observe quality and failure rates for a period, and then decide whether to expand.
4. Small-Sample Validation
Before a full switch, run a small-scale test with real samples. The steps are:
- Sample extraction. Stratify by task type and take 200–300 real requests. The sample must cover both high-frequency scenarios and edge cases — do not cherry-pick easy examples.
- Define the standard. Create a reference answer for each sample, or define a scoring rubric and have at least two people score independently, resolving disagreements afterward.
- Run uniformly. Run the same inputs on both the primary model and the candidate model, recording token usage and elapsed time for each request.
- Collect metrics. At minimum: cache hit rate, per-request cost (using the formula from Section 1), P95 latency, failure rate (including 429s, timeouts, and format errors), and quality pass rate.
- Interpret the results. With a 200-sample test, if the quality pass rate is near 50%, the margin of error at 95% confidence is about ±7%. If the difference between two models is smaller than this margin, no conclusion can be drawn — enlarge the sample or redesign the test.
Acceptance criteria should be defined before testing, not after. A reference example: the candidate model’s quality pass rate is no lower than 95% of the primary model’s, failure rate does not exceed 2%, P95 latency stays within the range the business can tolerate, and per-request cost is below the primary model’s calculated value. These thresholds should be adjusted to the business’s fault tolerance.
Rollback conditions should also be written down in advance. For example, if the failure rate exceeds the threshold for a full day after launch, or the sampled quality pass rate drops noticeably, immediately revert all traffic to the primary model and retain the logs for analysis.
5. Model Selection Checklist
When evaluating candidate models, record each item in the table below and fill in the data for all candidates in the same table to enable side-by-side comparison.
| Checklist Item | What to Record |
|---|---|
| Input price | Uncached input rate, with the billing unit noted (e.g., per million tokens) |
| Output price | Output token rate |
| Cache write price | Whether billed separately, write conditions, minimum cacheable length |
| Cache read price | Rate on a hit, and cache TTL |
| Long-context billing | Whether tiered, and the rate beyond the threshold |
| Rate limits | RPM, QPS, and TPM caps for the tier |
| Context window | Maximum input length per request |
| Output limit | Maximum output tokens per request |
| Latency and availability | P95 latency, SLA commitment, service regions |
| Rejected-request billing | Whether 429s, timeouts, and retried requests are billed |
| Price validity | Effective date of the price list and how changes are notified |
Once the table is complete, decisions can be made based on the costs computed from real billing data.
