LLM API Costs: Why the Same Token Prices Can Produce Very Different Bills
Identical per-token prices do not guarantee identical monthly LLM API bills. This article explains how caching, batch processing, subscriptions, billing windows, and regional pricing affect actual costs. A worked example, a Python estimator, and a practical evaluation framework show how to compare providers using real usage rather than headline rates.
1. Why Identical Token Prices Can Lead to Different Bills
Different platforms often advertise the same usage-based prices for the same model. Teams may therefore assume that choosing the same model means paying the same amount. In production, however, monthly bills can differ substantially.
The difference usually comes from billing rules rather than headline rates. A pricing table lists base prices per million tokens, but the actual bill also depends on how much input qualifies for cached pricing, whether tasks can run through an offline batch service, and when requests are processed. Together, these factors can produce very different costs for the same workload.
Comparing LLM API costs therefore requires more than checking token prices. Start by breaking the bill into its components, then estimate each one.
2. Understanding the Billing Components
LLM API pricing commonly includes the following dimensions.
2.1 Input, Output, and Cached Input
Input and output tokens are usually priced separately, with output tokens typically costing substantially more. Some platforms also offer a lower rate for input tokens that hit a cache.
A cache hit occurs when a request shares an identical prefix with a recent request, allowing the server to reuse previously computed intermediate results. This can deliver significant savings for workloads with repeated prefixes, such as fixed system prompts, question answering over long documents, and multi-turn conversations.
2.2 Offline Batch Discounts
Batch APIs let teams submit multiple requests for processing within a more flexible time window, usually at a discount. They suit tasks such as data labeling, offline summarization, and overnight report generation that do not require immediate responses.
The trade-off is latency. A workflow that needs responses within seconds generally cannot use this processing path.
2.3 Subscriptions and Overage Charges
Some platforms offer subscriptions that include a usage allowance for a fixed monthly fee, with additional usage billed separately. Whether a subscription is economical depends on two factors: whether actual usage consistently justifies the included allowance, and whether overage rates are competitive.
Some subscriptions also have time-based rules, such as larger allowances or lower prices during specific periods. Evaluate these rules against the timing of your actual requests.
2.4 Free Credits and Regional Differences
New models may come with a free token allowance for evaluation and small-scale testing. These credits can offset usage costs, but they typically have expiration dates and eligibility restrictions.
Region can also affect pricing. The same platform may charge different rates across deployment regions, while cross-region requests can introduce network latency. Include region in the comparison and confirm that data storage locations meet your compliance requirements.
2.5 Model Updates and Retirement
Older model versions may enter a retirement period, become unavailable to new users, and eventually be discontinued. Moving to a newer version requires regression testing and prompt adjustments. Include that migration effort when estimating long-term costs.
3. How Caching Changes API Costs
Caching is one of the largest individual contributors to billing differences and deserves a closer look.
3.1 How Prefix Reuse Works
An LLM computes internal states as it processes input tokens. If two requests begin with an identical sequence, the server can reuse the computation for that shared prefix. Eligible input tokens are then billed at the cached-input rate.
Request structure therefore directly affects cost. Place fixed instructions and reference documents at the beginning of the prompt, followed by the changing user question, to improve prefix reuse.
By contrast, inserting a timestamp or random ID before otherwise fixed content changes the prefix on every request and can prevent cache hits.
3.2 Cache Writes and Time to Live
Some platforms charge separately for cache writes. Writing to the cache may cost more than processing ordinary input, and cached content has a time to live, or TTL. Common settings include five minutes or one hour. Once the cache expires, a later request must populate it again.
Choosing a TTL involves a trade-off:
- Longer TTL: Higher write costs, but requests spaced farther apart may still hit the cache.
- Shorter TTL: Lower write costs, but the cache may expire between requests.
A short TTL is often more economical for closely spaced requests. A longer TTL may be worthwhile when requests arrive less frequently but still reuse the cached content before it expires.
3.3 Estimating the Effective Input Rate
Let:
hbe the share of input tokens served from cache.P_inbe the standard input price.P_hitbe the cached-input price.
The effective input price is:
Effective input price = h × P_hit + (1 − h) × P_in
Increasing the cache hit ratio from 30% to 70% can substantially reduce the effective input rate. Improving cache utilization can therefore be more valuable than finding a slightly lower headline price.
4. A Worked Monthly Billing Example
The following hypothetical prices illustrate the calculation. They do not represent any platform’s actual rates. All monetary values are in Chinese yuan (CNY).
Assume the following monthly usage:
- Total input: 500 million tokens, including 300 million cache-hit tokens and 200 million cache-miss tokens.
- Total output: 50 million tokens.
- Example prices per million tokens: CNY 10 for uncached input, CNY 1 for cached input, and CNY 50 for output.
Under standard usage-based billing:
| Component | Calculation | Cost |
|---|---|---|
| Uncached input | 200 × CNY 10 | CNY 2,000 |
| Cached input | 300 × CNY 1 | CNY 300 |
| Output | 50 × CNY 50 | CNY 2,500 |
| Total | CNY 4,800 |
Now assume every request is eligible for offline batch processing and the batch price is 60% of the standard price across these components:
CNY 4,800 × 60% = CNY 2,880
The difference is CNY 1,920, a 40% reduction.
If the cache hit ratio also increases from 60% to 80%, input costs fall further while output costs remain unchanged.
This example highlights three major cost drivers: the proportion of output tokens, the cache hit ratio, and eligibility for offline processing. Headline token prices are only one part of the calculation.
5. Turn Pricing Rules into a Reusable Cost Estimator
When evaluating platforms, encode their pricing rules in a reusable function rather than relying on mental arithmetic. The following simplified Python example demonstrates the calculation. Replace its inputs with actual prices and usage measurements.
from dataclasses import dataclass@dataclassclass Pricing:input_price: float # CNY per million uncached input tokenshit_price: float # CNY per million cached input tokensoutput_price: float # CNY per million output tokensbatch_discount: float # Batch price multiplier; 1.0 means no discount@dataclassclass Usage:input_tokens_m: float # Total input tokens, in millionshit_ratio: float # Cache hit ratio, between 0 and 1output_tokens_m: float # Total output tokens, in millionsbatch_ratio: float # Share eligible for batch processing, from 0 to 1def estimate_monthly_cost(p: Pricing, u: Usage) -> float:if not 0 <= u.hit_ratio <= 1 or not 0 <= u.batch_ratio <= 1:raise ValueError("Ratio parameters must be between 0 and 1")hit_tokens = u.input_tokens_m * u.hit_ratiomiss_tokens = u.input_tokens_m - hit_tokensrealtime_cost = (miss_tokens * p.input_price+ hit_tokens * p.hit_price+ u.output_tokens_m * p.output_price)batch_cost = realtime_cost * u.batch_ratio * p.batch_discountrealtime_part = realtime_cost * (1 - u.batch_ratio)return realtime_part + batch_costif __name__ == "__main__":pricing = Pricing(10, 1, 50, batch_discount=0.6)usage = Usage(500, hit_ratio=0.6, output_tokens_m=50, batch_ratio=1.0)print(round(estimate_monthly_cost(pricing, usage), 2))
The value of this function is that it makes cache utilization, batch eligibility, and output volume explicit. Teams can calculate these inputs from real request logs and compare different pricing arrangements.
The simplified calculation assumes the batch-eligible share has the same usage mix and cache hit ratio as the overall workload, and that the batch multiplier applies uniformly. Actual billing rules must determine whether those assumptions hold.
The example also excludes cache-write fees, subscription allowances, and time-based rates. Include these in a production estimator to avoid discrepancies with the actual bill.
6. A Framework for Comparing Providers
Before comparing individual platforms, work through the following steps.
6.1 Separate Real-Time and Offline Traffic
Divide requests into real-time and offline workloads. Real-time requests need responses within seconds; offline tasks can tolerate delays of minutes or hours.
Offline work is a candidate for batch processing. For real-time traffic, compare usage-based pricing with suitable subscription plans.
6.2 Assess Prefix Reuse
Review prompt structure. Are fixed instructions, examples, and documents placed at the beginning? Does changing content appear at the end?
If the structure can be improved, optimize it before comparing prices.
6.3 Compare the Full Billing Rules
For the same model and usage, list each provider’s billable components and enter them into the estimator. Focus on three scenarios:
- All traffic billed on a usage basis.
- A subscription with overage charges.
- A mixed approach that moves eligible requests to batch processing.
A plan that is cheapest within one usage range may become expensive when demand changes. If usage fluctuates, evaluate the risk of exceeding the included allowance. Underestimating the upper end of demand is a common reason subscription costs exceed expectations.
6.4 Include Migration and Operational Costs
Switching an existing integration involves more than changing an API endpoint. Costs may include API adaptation, prompt regression testing, monitoring and alerting changes, and team training.
If two platforms differ in price by only a few percentage points but migration requires weeks of work, retaining the current integration and optimizing usage may be the better choice.
7. Practical Ways to Reduce LLM API Costs
These practices apply broadly across LLM API workloads and do not depend on a particular platform.
Keep prefixes fixed and suffixes dynamic. Place system prompts, tool definitions, and reference documents at the beginning of requests, keeping repeated content byte-for-byte identical.
Control output length. Output tokens often cost more than input tokens. Avoid unnecessary long-form generation. Requesting only the required structured fields, such as specific JSON fields, can also reduce output volume.
Consolidate small requests. Where appropriate, combine or queue consecutive short requests from the same user at the application layer to reduce repeated prefix processing.
Move offline work out of the real-time path. Send labeling, bulk summarization, and data-cleaning tasks through batch APIs when their latency requirements allow it.
Record and analyze usage. Track token counts, cache hit ratios, and latency by model, workload, and time period. Without measurements, it is difficult to identify the most effective optimization.
Set budget alerts. Establish monthly budget thresholds for each project and notify owners as spending approaches the limit. This helps catch abnormal usage before it creates a large overrun.
Track model lifecycles. Monitor retirement schedules and reserve time for migration so that a forced shutdown does not trigger an unplanned switch.
8. Common Misconceptions
“The listed prices are identical, so switching is straightforward.”
Identical headline prices only establish that base rates match. Caching, batch processing, subscriptions, and regional rules can still change actual spending. Recalculate costs using real usage before switching.
“A longer cache TTL is always better.”
Longer TTLs can increase cache-write costs. If cached content is not reused before expiration, the write expense provides no savings. Choose a TTL based on the distribution of intervals between requests.
“Batch discounts apply to every workload.”
Batch processing does not provide the response-time guarantees required by real-time interactions. Putting interactive traffic into an offline queue can leave users waiting and degrade the experience.
“Subscriptions are always cheaper than usage-based billing.”
A subscription is valuable only when usage consistently justifies its fixed fee and included allowance. At low usage levels, part of the monthly payment may be wasted.
“The lowest price is the best choice.”
Cost optimization depends on reliable service. If a low-cost option frequently rate-limits requests during peak periods, retries and fallback requests may offset the apparent savings.
9. Conclusion
Monthly LLM API costs reflect multiple billing dimensions. Token prices are only the starting point: caching, offline batch processing, subscription allowances, time-based rules, and regional differences can all change the cost of the same workload.
Start with measured usage, identify every relevant billing component, and compare options with a reusable estimator. Then account for migration and operational costs before making a decision.
Consistently monitoring usage and improving request structure often produces more dependable savings than switching providers solely for a lower advertised rate.
