Same Unit Price, Different Bills: Demystifying and Controlling LLM API Costs
While large language model (LLM) API services may share identical base prices across different providers, actual monthly bills can vary significantly. This article breaks down the key factors influencing LLM API costs, including token type pricing, cache rules, batch discounts, and subscription plans. It further provides a cost estimation model and practical strategies for selecting the right billing options to optimize your LLM expenditures.
Why the Same List Price Leads to Different Bills
The list price is merely one input into the cost equation. Actual expenditure is determined by three components: the consumption volume of various token types, the unit price applicable to each token type, and the billing rules applied on top, such as batch discounts, subscription offsets, free tiers, and caching rules. Therefore, when comparing service costs, you should first analyze your usage structure and apply the billing rules accordingly, rather than simply looking at the first line of the pricing table.
1. Deconstructing the Billing Structure
1.1 Separate Pricing for Input, Cache Hits, and Output
LLM API calls are typically billed by token and at least distinguish between three types: uncached input tokens, cached input tokens, and output tokens. The unit price for output is usually much higher than for input, while the cache hit price is only a fraction of the standard input price. The same total number of tokens can yield vastly different costs depending on their structure. Long system prompts combined with fixed knowledge segments across multiple turns can generate a large number of reusable prefixes, significantly reducing costs upon cache hits. Conversely, tasks generating long texts have a high output proportion, shifting the cost burden to the output unit price.
1.2 Cache Writes and TTLs
Some platforms automatically identify repeated prefixes and enable caching, but cache writes may be billed separately, and default Time-to-Live (TTL) configurations vary. A common design offers two tiers: a short TTL (a few minutes) and a long TTL (about an hour). Writing to long TTLs costs more but is easier to hit when request intervals are lengthy. If the interval between requests exceeds the TTL, the cache expires, rendering the previous write fees useless. Whether a long TTL is worthwhile depends on the average request interval and the reuse frequency of the same prefix.
1.3 Batch (Offline) Discounts
Latency-insensitive tasks, such as data cleaning, offline summarization, and batch tagging, can usually be submitted as batch jobs in exchange for a discount, typically expressed as a percentage of the standard unit price. Two things must be noted when using batch channels. First, batch jobs are asynchronous with a completion window, making them unsuitable for real-time scenarios. Second, the discount may only apply to specific models. Submitting real-time requests as batch tasks causes latency issues, while calling offline tasks in real-time results in unnecessary overspending.
1.4 Pay-As-You-Go vs. Subscriptions
Pay-as-you-go billing offers flexibility for workloads with high volatility or unstable usage. Subscription or prepaid plans exchange a fixed fee for a certain quota or discount, suitable for stable and predictable workloads. Whether a subscription is cost-effective depends on whether actual usage can max out the quota. If the plan charges pay-as-you-go for overages, you must calculate the unit price for the excess and the distribution of quota usage throughout the day, as concentrated consumption during peak hours may significantly increase overage costs.
1.5 Time-of-Use Rules
Some services apply different billing rules for peak and off-peak hours. If your business has many deferrable requests, scheduling them during off-peak or designated hours may secure a lower effective unit price. Before using such rules, verify the billing time zone and ensure request timestamps align with it. Time zone misalignment can prevent expected discounts from taking effect.
1.6 Free Tiers and Unlisted Items
Newly launched models often come with free tiers. When calculating costs, treat the free quota as a limited resource, derive the long-term cost after deducting its impact, and plan a migration strategy before the quota is exhausted. Items marked as “unlisted” or “unspecified” in the pricing table do not necessarily mean free. Always refer to the official billing documentation and verify actual charges through small-scale tests before formal use.
1.7 Regions and Compliance
The unit price for the same service may vary by region. Overseas regions are typically more expensive due to data center costs, compliance requirements, and network routing. If your service is already deployed in a specific region, evaluate latency, data compliance requirements, and total cost simultaneously before migrating; do not just compare unit prices.
1.8 Model Iterations and Deprecations
Older models may stop accepting new users and be deprecated after an announced date. When migrating to a new model, the unit price, output style, context length, and rate limits may all change. Cost estimates should be based on the actual measured usage of the new model rather than directly applying the old model’s usage data.
2. Building a Cost Estimation Model
The core of cost estimation is breaking down the bill into independently calculable items and applying rules to each. The following example uses hypothetical prices to demonstrate the method; the values do not represent any actual service’s pricing.
PRICE = {"input": 10.0, "cache_hit": 1.0, "output": 50.0} # Cost per million tokens, hypothetical valuesdef monthly_cost(usage_m, price, batch_discount=1.0):"""usage_m: Monthly usage per token type (in millions); batch_discount: Discount factor for batch tasks"""return batch_discount * sum(usage_m[k] * price[k] for k in price)online = {"input": 800, "cache_hit": 3200, "output": 300}offline = {"input": 1200, "cache_hit": 0, "output": 400}list_total = monthly_cost(online, PRICE) + monthly_cost(offline, PRICE)actual_total = monthly_cost(online, PRICE) + monthly_cost(offline, PRICE, 0.6)print(f"All at list price: {list_total:.0f} units")print(f"Offline tasks at 40% off: {actual_total:.0f} units")
The execution result is: 58200 units at full list price, and 45400 units with a 40% discount on offline tasks, reducing the total cost by approximately 22%.
Three points require attention during estimation. First, usage should be split into real-time and offline statistics because the applicable discounts differ. Second, the number of cache hit tokens should be taken from the provider’s usage details or request logs rather than estimations. Third, whenever prices or billing rules change, re-run the estimation to ensure the conclusions remain valid.
3. Selection Strategy
You can follow this sequence to make your selection:
- Distinguish real-time from offline tasks first. Prioritize batch channels for offline tasks, and reserve pay-as-you-go or subscriptions for real-time tasks.
- Evaluate usage stability. Use pay-as-you-go billing for volatile workloads, and consider subscription plans only after usage stabilizes.
- Calculate the cache hit rate. The more stable the prefixes, the higher the cache benefits, so prioritize optimizing the prompt structure.
