LLM API Billing Rules: Why the Same Unit Price Can Produce Different Monthly Bills
This article explains why LLM API bills can differ even when list prices match. It breaks down token categories, batch discounts, prefix caching and cache writes, subscription and overage billing, off-peak rules, and free quotas. It also provides a monthly cost model that incorporates batch share, a five-step vendor selection process, and a note on model version migration and lifecycle management.
1. Same Unit Price, Different Bills
The list price of an LLM service is only one dimension of billing. The same model often carries the same advertised price across different platforms, but the actual bill depends on how the API is called, cache hits, subscription structure, calling time windows, and free quotas. Comparing unit prices alone is like looking at only one multiplier in the billing formula.
Selection and cost optimization should therefore start with the usage structure. First determine how many input tokens and output tokens are consumed each month, how much of that can be reused, and then compare how different billing rules apply to that usage profile.
2. Breaking Down the Bill
Usage-based billing usually charges three token categories separately.
- Input tokens: system prompts, conversation history, retrieved document chunks, tool definitions, and similar content in a request.
- Cache-hit tokens: when a request prefix matches a recent request, the server reuses the processed prefix, and this part of the input is billed at a lower unit price.
- Output tokens: content generated by the model, usually billed at the highest unit price.
The monthly cost can be written as follows:
Monthly cost = input usage × input unit price + cache-hit usage × cache-hit unit price + output usage × output unit price + other fee items
Other fee items include cache write fees, subscription fees, overage fees, and similar charges. Most teams only track total token counts and do not record input, cache-hit, and output tokens separately, making it difficult to identify where optimization opportunities lie. At a minimum, request logs should record the input tokens, cache-hit tokens, output tokens, and business scenario for each call.
3. Four Types of Rules That Affect Cost
3.1 Batch Processing Discounts
Offline tasks such as overnight data cleaning, batch document summarization, and offline evaluation usually do not require immediate results. Some services provide batch submission APIs that return results within a longer completion window and charge a percentage of the standard unit price.
There are two prerequisites for using batch APIs: the task can tolerate latency, and the task can be submitted as a whole package. The discount ratio should be based on each platform’s official pricing page and should not be hard-coded in the architecture design.
3.2 Prefix Caching and Cache Writes
Many services automatically detect repeated request prefixes, such as fixed system prompts, long documents, and tool definitions. When a prefix is hit, the corresponding input portion is billed at a lower unit price.
This mechanism has two details that are easy to overlook.
- The cache has a validity period (TTL), and after it expires, the prefix must be written again.
- Some platforms charge separately for cache writes. The write unit price may be higher than regular input, and write unit prices may differ for different validity periods.
Therefore, the benefit of caching depends on the hit rate. If the same prefix is used only once, the write fee may offset all savings. If it is called repeatedly within the validity period, the savings can be significant.
The following code estimates the cost per call under different hit rates, helping determine whether it is worth optimizing the prefix structure:
def per_call_cost(prefix_tokens, dynamic_tokens, output_tokens,input_price, hit_price, write_price,hit_rate, price_unit=1_000_000):"""Estimate the cost per call (in the same unit as the prices).hit_rate: probability that the prefix cache is hit, between 0 and 1.Write cost is counted when the cache misses; the simplified model ignores repeated writes within the TTL."""miss_cost = prefix_tokens / price_unit * write_pricehit_cost = prefix_tokens / price_unit * hit_priceprefix_cost = hit_rate * hit_cost + (1 - hit_rate) * miss_costdynamic_cost = dynamic_tokens / price_unit * input_priceoutput_cost = output_tokens / price_unit * output_price_placeholder if False else 0return prefix_cost + dynamic_cost
The example above only illustrates the idea. In actual use, output fees should also be included, and the model should be adjusted according to the write rules in the official documentation. The core idea is to split the prefix cost into “hit” and “miss” parts and weight them by the hit rate.
3.3 Subscription Plans and Overage Billing
Subscription plans usually prepay a fixed fee in exchange for a lower effective unit price within a certain quota, with usage beyond the quota billed on a usage basis. Whether a subscription is worthwhile depends on whether monthly usage consistently falls within the quota.
Let the monthly usage-based cost be C, the subscription fee be F, and the usage-based charge for overage be E. The total cost of the subscription option is F + E. When F + E is less than C, the subscription is preferable.
This condition has two implications. When usage is low, the fixed fee becomes a sunk cost, and usage-based billing is more cost-effective. When usage is high, if the overage rate is high, the total cost may exceed usage-based billing. In addition, subscriptions often limit available models, calling channels, or concurrency limits, so coverage should be checked before selection.
3.4 Off-Peak and Time-Window Rules
Some platforms apply different pricing or quota rules to calls in different time windows. If the business has time flexibility, such as report generation, non-urgent content moderation queues, and overnight data synchronization, these tasks can be scheduled into more favorable time windows.
This type of optimization needs to be implemented at the task scheduling layer. A common approach is to assign priorities and deadlines to tasks and let the scheduler decide when to actually send requests. Urgent tasks go through the real-time channel, while other tasks enter a queue and wait for a suitable time window.
3.5 Free Quotas and Trial Periods
When a new model is first launched, the platform may provide a certain free quota. Such quotas are usually one-time or have a clear time window. They are suitable for functional validation, quality evaluation, and gradual rollout, and should not be used as the foundation of a long-term cost model.
4. Building a Cost Estimation Model
The following example incorporates the batch share into the calculation. Assume a business has 300 million input tokens, 600 million cache-hit tokens, and 60 million output tokens per month, and 30% of input and output can be shifted to batch tasks. The unit prices below are example assumptions and do not represent the actual prices of any platform.
from dataclasses import dataclass@dataclassclass Pricing:input_per_m: float # Regular input, CNY per million tokenscache_hit_per_m: float # Cache hit, CNY per million tokensoutput_per_m: float # Output, CNY per million tokensbatch_ratio: float = 1.0 # Price multiplier for batch tasks; 1.0 means no discount@dataclassclass Workload:input_tokens: int # Total monthly input tokens (excluding cache hits)cache_hit_tokens: int # Monthly cache-hit tokensoutput_tokens: int # Monthly output tokensbatch_share: float = 0.0 # Share that can be processed in batch, from 0 to 1def monthly_cost(p: Pricing, w: Workload) -> float:per_m = 1_000_000base = (w.input_tokens / per_m * p.input_per_m+ w.cache_hit_tokens / per_m * p.cache_hit_per_m+ w.output_tokens / per_m * p.output_per_m)realtime_share = 1 - w.batch_sharereturn base * (realtime_share + w.batch_share * p.batch_ratio)if __name__ == "__main__":pricing = Pricing(input_per_m=10, cache_hit_per_m=1,output_per_m=50, batch_ratio=0.6)workload = Workload(input_tokens=300_000_000,cache_hit_tokens=600_000_000,output_tokens=60_000_000,batch_share=0.3)print(f"Billed with the actual mix: {monthly_cost(pricing, workload):.0f} CNY")no_batch = Workload(input_tokens=300_000_000,cache_hit_tokens=600_000_000,output_tokens=60_000_000,batch_share=0.0)print(f"All real-time billing: {monthly_cost(pricing, no_batch):.0f} CNY")
Under the assumptions above, all real-time billing costs CNY 6,600, while the mixed batch approach costs CNY 5,808, a saving of about 12%. The saving depends entirely on the batch share and the discount ratio. The higher the batch share, the more obvious the saving.
The value of the model is that it lets teams replace assumptions with real data. It is recommended to run the model once a month with actual logs, reconcile the result against the bill, and check the statistical scope if there is a large deviation.
5. Selection Steps
Selection can proceed in the following five steps.
- Split the workload. Separate calls into real-time and offline categories, and count input, cache-hit, and output tokens separately.
- Measure the hit rate. Use real logs to calculate the proportion of repeated prefixes and the number of reuse events within the validity period.
- Compare billing forms. Calculate the cost of usage-based, batch, and subscription options on the same usage profile, and identify the break-even point.
- Include engineering costs. Consider API compatibility, migration effort, and monitoring and alerting investment. These costs can sometimes exceed unit price differences.
- Evaluate service quality. Confirm whether latency, concurrency quotas, availability commitments, and data processing terms meet business requirements.
In most cases, the conclusion from step 3 is the most intuitive, but steps 4 and 5 determine whether the final solution can run long term.
6. Model Version Migration and Lifecycle Management
LLM versions iterate quickly, and the retirement of older versions is common. Without advance planning, migration is often rushed before the deadline and introduces quality risks.
Recommended practices include the following.
