LLM API Cost Estimation: How Billing Rules Shape Your Actual Spend
LLM API pricing involves more than a per-token rate. This article explains six billing factors that affect actual costs, including input and output pricing, caching, reasoning tokens, promotional discounts, batch processing, and subscription credits. It also provides a Python estimator and a hypothetical pricing scenario for comparing costs on a consistent basis.
1. Why Published Token Prices Are Not Enough
LLM API prices are typically quoted per million tokens. Even when the same model has identical advertised prices across providers, the amount a team actually pays depends on three things: how usage is counted, which charges receive discounts, and when those discounts expire.
Comparing headline prices alone can therefore overestimate or underestimate actual spending.
This article does not recommend specific providers. Instead, it explains common billing factors and presents a cost estimation method using hypothetical prices. You can substitute your own rates and usage figures to compare costs on the same basis.
2. Six Billing Factors That Affect API Costs
2.1 Input and Output Price Differences
Most LLMs charge more for output tokens than input tokens, often by a factor of several times. Generating output requires autoregressive computation, producing tokens one at a time, which increases computational cost.
As a result, two workloads with the same total token count can have different costs: the one with a higher share of output tokens will cost more. When designing prompts, limiting output to the length the application actually needs can often save more than shortening the input.
2.2 Cache Hits and Cache Storage
Some platforms support prefix caching. When multiple requests share the same system prompt or long document prefix, the cached portion of the input is billed at a lower rate.
Two details matter:
- Prefix stability affects cache hits. Placing dynamic content at the end of a prompt can improve cache reuse.
- Cache storage may have a separate charge. Check the billing documentation rather than assuming storage is free.
2.3 Reasoning Tokens Count Toward Output Usage
Reasoning-capable models may generate intermediate reasoning before producing an answer. These tokens are often billed as output tokens, even when they are not included in the visible response.
Consequently, billable output can be several times longer than the answer the user sees. For cost estimates, sample the usage fields returned by the API and measure the ratio of billable output tokens to visible answer tokens. Do not estimate costs from visible answer length alone.
2.4 Promotional Discounts and Price Validity
Promotional prices are often described as temporary. If no end date is provided, do not assume the discount will remain available indefinitely.
Before deployment, build two cost scenarios: one using promotional prices and another using standard prices. When the promotion ends, costs can rise immediately, so teams need to budget for the increase or adjust usage in advance.
2.5 Offline Batch Discounts
Tasks such as data cleaning, bulk labeling, and offline summarization do not require immediate responses. Many platforms offer asynchronous batch APIs for these workloads at lower prices than their real-time APIs.
These jobs can be queued for off-peak execution, supporting high throughput at a lower unit cost. Before choosing an API mode, separate workloads that require real-time responses from those that can run offline.
2.6 Subscriptions and Credit Conversion
Subscription plans may convert usage into credits and deduct those credits as requests are processed. The effective conversion typically depends on both the price per credit and a model-specific multiplier.
To evaluate a subscription, convert credits back into a common currency and compare the result with pay-as-you-go pricing. Also check whether unused credits expire and whether credits can be used across models. Both rules affect the effective unit cost.
3. Building a Monthly Cost Estimate
A basic monthly estimate can be expressed as:
Monthly cost = (Uncached input tokens × Input rate+ Cached input tokens × Cached-input rate+ Output tokens × Output rate) × Discount multiplier
When rates are quoted per million tokens, divide the token-based subtotal by 1,000,000.
If the output estimate represents only the visible answer, multiply it by a reasoning factor to account for additional billable output. Derive this factor from sampled requests rather than guessing it. If your output estimate already includes all billable output tokens, use a factor of 1.0 to avoid double-counting.
The following Python function implements this calculation. Prices and results use Chinese yuan (CNY), matching the hypothetical example below. The same calculation works with another currency as long as all rates use that currency consistently.
def estimate_monthly_cost(monthly_requests: int,avg_input_tokens: int,avg_output_tokens: int,cache_hit_ratio: float,price_input: float, # CNY per million tokensprice_cache_hit: float, # CNY per million tokensprice_output: float, # CNY per million tokensreasoning_factor: float = 1.0,discount: float = 1.0,) -> float:"""Estimate monthly API costs in CNY."""if not 0.0 <= cache_hit_ratio <= 1.0:raise ValueError("cache_hit_ratio must be between 0 and 1")input_total = monthly_requests * avg_input_tokenscached_tokens = input_total * cache_hit_ratiouncached_tokens = input_total - cached_tokensoutput_total = monthly_requests * avg_output_tokens * reasoning_factorraw_cost = (uncached_tokens * price_input+ cached_tokens * price_cache_hit+ output_total * price_output) / 1_000_000return round(raw_cost * discount, 2)
Here, cache_hit_ratio represents the share of input tokens billed at the cached-input rate. The discount parameter is a multiplier applied to the calculated token charges.
The following example shows how to call the estimator with hypothetical prices. These figures are for calculation purposes only and do not represent any provider’s actual rates.
# Hypothetical rates for illustration onlyscenario = dict(monthly_requests=100_000,avg_input_tokens=2_000,avg_output_tokens=500,cache_hit_ratio=0.5,price_input=1.0,price_cache_hit=0.3,price_output=4.0,reasoning_factor=2.5,)standard = estimate_monthly_cost(**scenario)
This model estimates the token charges covered by its inputs. Any separately billed cache storage must be considered alongside that estimate. For meaningful comparisons, use the same workload assumptions across pricing scenarios and distinguish temporary discounts from standard rates.
