How to Recalculate LLM Inference Costs After an API Price Change
API price changes affect the cost structure, not just the unit price. This article shows how to rebuild a reusable token-based cost model, why older estimates systematically understate spend, and which engineering controls matter most: output compression, stable cacheable prefixes, time-of-day scheduling, model-tier routing, harness evaluation, and centralized gateway governance.
The real impact of a price change: not the unit price, but the cost structure
A large model API price adjustment looks like a change in unit prices, but what it really changes is the cost structure. Once the price ratios among input tokens, cache-hit tokens, and output tokens are reset, any estimation script, budget sheet, or model-selection conclusion that still uses the old prices will be inaccurate. The first step is therefore not to argue whether the new price is “expensive,” but to rebuild a reusable cost model.
A typical medium-sized coding session has a token mix roughly like this: about 50K new input tokens, about 200K cache-hit tokens, and about 30K output tokens. Note that cache hits are four times the new input. This means that in long-context, multi-turn coding workflows, repeated context is the main part of the bill, not the few lines the user typed in the current turn.
A reusable estimate model: split the bill into three parts
Let the three unit prices be p_in, p_cache, and p_out. The cost of a single session is:
cost = in_tokens * p_in+ cache_tokens * p_cache+ out_tokens * p_out
Using a set of illustrative prices (only to demonstrate the algorithm, not to represent any vendor’s actual quote): new input 1.0, cache hit 0.022, output 3.0, in USD per million tokens. Then:
- New input: 0.05 × 1.0 = 0.05
- Cache hit: 0.20 × 0.022 ≈ 0.0044
- Output: 0.03 × 3.0 = 0.09
- Total ≈ 0.144
Lower the output price to 0.6 and the input price to 0.15 (a lightweight model tier), and the same workload comes to roughly 0.036. The same work can cost three to four times more or less solely because of the model tier and price structure.
Two structural facts must go into team guidelines:
- Output price is usually several times the input price (3× in this example). In the example above, output is only about 6% of total tokens but contributes more than 60% of the cost. The conclusion is direct: compressing output saves more than pinching input.
- Cache-hit price is deliberately pushed very low (about 1/45 of input in this example). This means “put stable content into a cacheable prefix” is the highest-leverage optimization, not an optional one.
Why old estimates understate costs by more than half
If a team still uses a price table from several months ago, two sources of error compound: an overall increase in unit prices, and changes in peak/off-peak and rest-day policies (for example, weekends and holidays may be billed all day at the off-peak rate). Multiplied together, an off-peak period may already be about twice the old price, while peak periods can reach about four times. Any method that extrapolates today’s bill from an old answer will systematically underestimate it. The fix is simple: take prices out of the code, make them configurable, or read them from a billing interface. Do not hardcode them.
# Centralize pricing to avoid estimation drift from scattered hardcodingPRICING = {"flagship": {"in": 1.0, "cache": 0.022, "out": 3.0},"light": {"in": 0.15, "cache": 0.01, "out": 0.6},}def estimate(model, in_t, cache_t, out_t):p = PRICING[model]return in_t * p["in"] + cache_t * p["cache"] + out_t * p["out"]
Four common pitfalls and what to do instead
Pitfall 1: Watching input only and ignoring output. Output price is several times input price. Long explanations, repeated code echoes, and line-by-line diff narration all inflate the bill. What to do: state in the prompt “output only changed snippets and necessary explanation,” disable unnecessary verbose modes, and rewrite long files in segments rather than regenerating the entire file.
Pitfall 2: Resending stable context every turn. System prompts, coding standards, repository structure descriptions, and dependency versions are stable content. They should be fixed at the request prefix so they consistently hit the cache; volatile content (current file, current-turn instructions) should come later. A layered structure:
[Stable prefix · cacheable] system role + coding standards + repository structure + dependency versions[Semi-stable zone] current task context and constraints[Volatile zone] current-turn instructions + relevant code snippets
Pitfall 3: Ignoring time of day and date. Off-peak, peak, weekend, and holiday prices may differ. Deferrable work such as batch refactoring, batch test backfilling, and log analysis should be scheduled for off-peak periods; interactive debugging can stay in peak periods because its token volume is usually small.
Pitfall 4: Using one model for everything. Daily code changes, comment completion, and unit-test writing are lightweight tasks that can use a lightweight model tier at roughly one quarter of the flagship cost. Only complex reasoning and cross-file refactoring need to switch back to the flagship tier. Make routing explicit in engineering rather than relying on manual switching:
def route(task):if task.complexity in ("multi_file_refactor", "root_cause_analysis"):return "flagship"return "light"
Capability is not the same as out-of-the-box performance: the harness matters more than it seems
One often overlooked fact is that the same model can differ more across different runtime harnesses than different models differ from each other. A model with strong base capability but insufficient post-training and alignment often performs modestly under the default harness. In internal experiments, customizing tool-call protocols, context-compression strategies, and failure-retry logic for that model can significantly exceed the completion rate of a “strong model + default harness” combination on complex agentic tasks.
This explains why “switch models” is often not the optimal move. A practical order of operations is: fix the evaluation set first, then adjust the harness in sequence (tool descriptions, error-feedback return, context trimming, subtask decomposition), and only then compare models. The evaluation set should contain automatically judgeable pass conditions; otherwise, tuning degenerates into guesswork.
Integration and governance: keep the interface layer neutral
Most platforms provide both a general REST interface and an endpoint compatible with mainstream coding-assistant protocols. The latter can be filled directly into the base URL and token configuration fields of a coding tool, with the model name set according to the platform documentation, without changing upper-layer logic. From an engineering perspective:
- Use a unified gateway to wrap model calls, hide protocol differences, and make it easy to switch tiers and vendors at any time.
- Record the three token segments and estimated cost for every request to create observability dashboards and budget alerts.
- Set threshold alerts for cache hit rate. A sudden drop usually means the prefix has been polluted by volatile content.
- Validate prompt-template prefix stability in CI to prevent a single change from invalidating the entire cache.
Conclusion
After a price change, the focus of cost optimization shifts from “finding a cheaper unit price” to “changing the cost structure”: compress output, stabilize prefixes, schedule off-peak, and route across model tiers. At the same time, put model selection back into the context of harness and evaluation systems; do not judge a model from a single experience under default settings. Make pricing configurable, usage observable, and evaluation sets fixed. Once these three things are done, any future price adjustment is just a configuration change, not a budget incident.
