Rising LLM API Costs: Cost Modeling, Alternatives, and Optimization
This article explains how usage-based LLM API price changes affect architecture decisions. It covers billing components, a repeatable daily cost model with sample code, the role of cache hit rate, and trade-offs among keeping the current model, switching providers, self-hosting open-weight models, and hybrid routing.
Introduction: Why Price Changes Affect Architecture Decisions
LLM APIs are billed by usage, so unit price changes pass directly into every request. Small personal projects with low call volumes are affected only to a limited extent. The situation is different for businesses with hundreds of thousands of requests per day and long inputs and outputs. A price adjustment of the same percentage can multiply the monthly bill and force teams to re-evaluate model selection, invocation patterns, and feature boundaries.
The core of responding to price changes is therefore not judging whether a particular provider deserves long-term cooperation. It is establishing a reusable cost model that compares price, usage, and output quality in the same table. The methods discussed in this article apply to any model service billed by token.
1. Understanding the Billing Structure
Common usage-based billing usually includes the following types of charges:
- Regular input tokens: prompts in the request, conversation history, retrieved materials, and so on.
- Output tokens: content generated by the model.
- Cache-hit input tokens: the part of the input whose prefix matches previous requests and can be reused by the server. Its unit price is usually significantly lower than that of regular input.
- Time-of-day differences: some services price peak and off-peak calls differently, with lower unit prices during off-peak periods.
The weight of different billing items depends on the business pattern. Q&A applications have shorter inputs and longer outputs, so the output unit price has a greater impact. Retrieval-augmented applications have long and highly repetitive inputs, so the cache hit rate has a greater impact on total cost. Long-document summarization applications are mainly affected by the input unit price.
A price adjustment is often not proportional across all items. The increases for output unit price, regular input unit price, and cache-hit unit price may differ greatly. Looking only at an average increase can easily underestimate cost changes in some scenarios. Therefore, cost modeling should calculate each billing item separately rather than applying a single overall increase.
2. Building a Cost Model
The first step in cost modeling is to obtain real usage data, including daily request count, average input tokens, average output tokens, and cache hit rate. These data should come from logs or billing details, not from experience-based estimates.
The basic formula is as follows:
Daily cost = regular input tokens × regular input price + cache-hit tokens × cache-hit price + output tokens × output price
The example below uses hypothetical values only to demonstrate the calculation method. It does not represent any real price:
def daily_cost(requests, in_tokens, out_tokens, hit_rate,in_price, out_price, hit_price_ratio):# Price unit: CNY per million tokens# in_tokens, out_tokens: average tokens per request# hit_price_ratio: cache-hit price as a share of regular input pricetotal_in = requests * in_tokens / 1e6total_out = requests * out_tokens / 1e6hit_in = total_in * hit_ratemiss_in = total_in - hit_incost_in = miss_in * in_price + hit_in * in_price * hit_price_ratiocost_out = total_out * out_pricereturn cost_in + cost_out# Assumptions: 100,000 requests per day, 2,000 input tokens and 500 output tokens per request, 20% cache hit rate# Before price change: input 1 CNY, output 4 CNY, cache hit at 10% of input pricebefore = daily_cost(100_000, 2000, 500, 0.2, 1.0, 4.0, 0.1)# After price change: assume both input and output prices rise to 3x their original levelsafter = daily_cost(100_000, 2000, 500, 0.2, 3.0, 12.0, 0.1)print(round(before, 2), round(after, 2)) # Output: 364.0 1092.0
The example shows that under the assumed 3x price increase, daily cost rises from CNY 364 to CNY 1,092. Next, consider the effect of caching. Raising the cache hit rate to 60% lowers the post-change daily cost to CNY 876, about 20% less than at a 20% hit rate. This indicates that in a price-increase environment, improving the cache hit rate can deliver benefits comparable to negotiating or switching models, with lower implementation cost.
Two more points should be noted during cost modeling. First, average token counts change with the business and need to be updated regularly. Second, cost should be modeled separately by functional module. A system may contain both high-value complex reasoning and a large number of low-value classification tasks; combined modeling hides the real sources of cost.
3. Comparing Alternatives
There are usually four paths for responding to price increases, each with trade-offs.
- Keep the current model and accept the price increase while reducing cost through optimization. This suits scenarios with high quality requirements and high migration risk.
- Switch to another commercial model service. Migration cost is lower than self-hosting, but the service is still exposed to price volatility. Evaluate provider stability, rate-limit policies, and terms of service.
- Self-deploy open-weight models. Unit cost can be reduced at sufficient scale, and data is easier to keep in the internal environment. The trade-offs are GPU resources, operations staffing, and continuous validation of model capability.
- Hybrid routing: handle simple requests with smaller models or cache, and call large models only for complex requests. This usually gives a good balance of cost and quality, but has the highest architectural complexity.
