Modeling Cache-Aware Billing and Subscription Plan Costs for LLM APIs

    Price per million tokens alone can misrepresent LLM API costs. This article explains how cache hits, uncached input, output tokens, peak and off-peak pricing, retries, and subscription quota utilization together determine real spend. It covers an effective unit cost formula, a worked example, a method for converting subscription plans into effective costs, and a checklist for reducing costs.

    Modeling Cache-Aware Billing and Subscription Plan Costs for LLM APIs

    When evaluating LLM API costs, the most commonly misused metric is the “price per million tokens.” A nominal unit price describes only the list price of one token category. Actual bills depend on cache hits, uncached input, the output ratio, peak and off-peak hours, failed retries, context trimming, and how fully a subscription plan’s quota is used. Two services with different list prices can reverse their true cost ranking once cache hit rates and input-output structures differ. Engineering teams therefore need a cost model built on consistent definitions, rather than a comparison of one unit price.

    1. Breaking Down the Billing Components

    General LLM API billing typically divides tokens into three categories:

    1. Cache hit tokens: Context prefixes reused from cache, billed at a lower unit price.
    2. Uncached input tokens: Input tokens newly processed by the model in the current request, billed at the standard input price.
    3. Output tokens: Tokens generated by the model, usually with the highest unit price.

    If a provider supports peak and off-peak pricing, the same token category may have different prices at different times. Under a subscription plan, the monthly fee must be converted into an “actual usable token cost.” Cost comparisons therefore need at least four dimensions: pricing structure, token mix, time distribution, and plan constraints.

    2. The Effective Cost Formula and Common Definition Pitfalls

    Let T be total token consumption, h the cache hit token share, i the uncached input token share, and o the output token share, with h + i + o = 1. Let p_cache, p_input, and p_output be the cache, input, and output unit prices. Then:

    C = T × (h × p_cache + i × p_input + o × p_output)

    The average effective unit price is:

    p_eff = C / T = h × p_cache + i × p_input + o × p_output

    The formula looks simple, but its definitions must be consistent. Many billing systems report cache rates as a share of input tokens, not of total tokens. If total input is I, total output is O, and the input cache hit rate is h_i, then:

    C = I × [h_i × p_cache + (1 - h_i) × p_input] + O × p_output

    The two definitions give similar results when output is small. In long-output, multi-turn, or code generation workloads, however, the gap can significantly change the estimate. Engineers should take the actual counts of the three token types from billing records or usage logs instead of relying on rough ratios.

    Worked example: assume p_cache = 0.1 × p_input and p_output = 4 × p_input, for illustration only. If cache hits account for 98% of total tokens, uncached input for 1.5%, and output for 0.5%, the average effective price is 0.98 × 0.1 + 0.015 × 1 + 0.005 × 4 = 0.133 × p_input. If cache hits drop to 95%, uncached input rises to 4.5%, and output stays at 0.5%, the average effective price becomes 0.95 × 0.1 + 0.045 × 1 + 0.005 × 4 = 0.16 × p_input, an increase of about 20%. Cache hit rate has a large, direct effect on cost, so the cache unit price alone is not enough to judge it.

    3. Weighting Peak and Off-Peak Pricing by Time

    The key point is not simply that off-peak prices are lower. What matters is whether the workload can move to off-peak hours. If off-peak prices are lower but business load concentrates in peak hours, the actual average price must be weighted by hourly usage:

    p_avg = Σ(p_t × q_t) / Σq_t

    Here p_t is the unit price in period t, and q_t is the token volume in that period. For deferrable workloads such as offline batch processing, log summarization, data cleaning, and batch code review, queues can smooth peaks and schedule most of the load into low-price periods. For latency-sensitive tasks such as online chat, real-time completion, and interactive programming, scheduling room is limited, so estimates should be conservative.

    Some subscription plans also restrict peak hours or apply stricter rate limits to peak-hour calls. In that case, a plan’s nominal quota does not equal its actual usable quota. If business peaks overlap with plan restrictions, quota may go unused while requests are throttled, and the real unit cost rises.

    4. Converting Subscription Plans: Monthly Fee Divided by Effective Usable Tokens

    Subscription plans are often marketed as “X tokens per month” or as equivalent to a given amount of pay-as-you-go API usage. A more rigorous calculation is:

    Effective unit cost of a plan = monthly fee / (nominal quota × availability × success rate)

    Availability is affected by peak-hour limits, concurrency caps, and rate limits. Success rate is affected by failed retries, timeouts, and context overflows. If a plan has low, medium, and high tiers, comparing monthly fees alone is not enough. Compare the quota the business can actually consume and the peak concurrency each tier supports. Lower tiers suit light personal development. Higher tiers suit shared team use, but sharing creates quota contention and queuing costs.

    A practical rule: when business token demand is stable, cache hit rates are high, and the plan’s rate limits are acceptable, a subscription plan may lower unit cost. When demand fluctuates widely, peaks are concentrated, or the workload needs high concurrency or large outputs, pay-as-you-go billing makes the budget easier to control. A subscription does not guarantee a lower cost. It shifts price risk from usage volatility to quota utilization risk.

    5. Engineering Optimization Checklist

    To reduce real costs, consider the following:

    • Stable prefix reuse: Place system prompts, tool descriptions, and fixed knowledge snippets at the front of the context, so that prefix changes do not invalidate the cache.
    • Context trimming: Keep only necessary history to avoid inflating input tokens with unneeded long context.
    • Output control: Use clearer format constraints and length limits to reduce redundant output, since output tokens usually carry the highest unit price.
    • Retry governance: Apply backoff and idempotency policies for timeouts, rate limits, and format errors to avoid paying for repeated requests.
    • Billing monitoring: Break usage down by cache hits, uncached input, output, time period, and business line, and maintain a daily cost dashboard.
    • Load testing: Run A/B tests with real request distributions to verify cache hit rates and plan quota utilization, rather than relying only on short text samples.

    Illustrative pseudocode:

    1. function estimate_cost(total_tokens, cache_ratio, input_ratio, output_ratio,
    2. p_cache, p_input, p_output):
    3. assert cache_ratio + input_ratio + output_ratio == 1
    4. return total_tokens * (
    5. cache_ratio * p_cache +
    6. input_ratio * p_input +
    7. output_ratio * p_output
    8. )
    9. function subscription_cost(monthly_fee, nominal_tokens, availability, success_rate):
    10. effective_tokens = nominal_tokens * availability * success_rate
    11. return monthly_fee / effective_tokens

    6. Conclusion: Making Decisions on a Consistent Basis

    Comparing the real cost of LLM APIs should follow a three-step process: first align definitions, then plug in parameters, and finally run a sensitivity analysis. At minimum, test high and low scenarios for cache hit rate, output share, peak and off-peak distribution, and plan availability, and check whether the cost ranking holds. For high-cache workloads, the cache unit price and hit stability are the key factors. For output-heavy workloads, the output unit price and length control matter most. For subscription plans, quota availability and peak-hour restrictions are the key factors. Only by converting nominal unit prices into effective unit costs can developers and organizations make cost decisions that are verifiable, auditable, and sustainable to optimize.