LLM API Cost Breakdown: Why the Same Unit Price Can Produce Half the Bill

    This article explains why identical per-token prices can still produce very different LLM API bills. It breaks down the billing rules that affect cost—input, cache-hit input, and output pricing; batch discounts; subscription overage; free quotas and tiered pricing; and regional pricing—then walks through an example calculation, a Python cost function, cache-friendly prompt structure, and real-time versus offline task design.

    1. Same Unit Price, Different Bill

    The pay-as-you-go unit price for the same model is often identical across platforms, because most platforms refer to the same official price list. But what developers actually pay is the bill amount, which is determined by usage, unit price, and a set of billing rules. These rules include volume discounts, cache billing, subscription plans, free quotas, and regional price differences. Comparing only unit prices misses the largest source of variation.

    A monthly bill can be written as a simplified formula:

    Bill amount = Σ (usage of a given type × unit price for that type × rule adjustment factor) + fixed fees

    Here, usage is divided into three categories: ordinary input, cache-hit input, and output. Adjustment factors come from discounts and plan credit rules. Fixed fees refer to subscription monthly fees.

    2. Five Types of Billing Rules That Affect the Bill

    2.1 Input, Cache Hits, and Output

    LLM APIs usually split Token pricing into three categories: ordinary input, cache-hit input, and output. The output unit price is often several times the input unit price. When long prefixes such as system prompts, knowledge base snippets, and tool definitions remain unchanged across multiple requests, the server can reuse the processed prefix, and the hit portion is billed at a lower unit price.

    There are two points to note. First, some services charge separately for cache writes, and the write unit price may be higher than ordinary input. Caching is cost-effective only when the reuse count is high enough. Second, caches have a time to live (TTL), commonly ranging from a few minutes to an hour. A longer TTL increases write cost but can improve hit rates in low-frequency request scenarios.

    2.2 Batch Offline Calls

    Batch offline interfaces allow a large number of requests to be submitted at once. The server processes them asynchronously on idle resources, and results are usually returned within hours. Many platforms offer a discount as a percentage of the standard price. This type of interface is suitable for data labeling, batch document summarization, offline evaluation, and report generation. It is not suitable for chat or features that require second-level responses.

    2.3 Subscription Plans and Overage Billing

    A subscription plan usually consists of a fixed monthly fee, an included quota, and pay-as-you-go overage. The cost can be written as:

    Cost = monthly fee + max(0, actual usage - included quota) × overage unit price

    When usage is far below the included quota, the plan is not cost-effective. When usage approaches or exceeds the quota, the plan cost may be significantly lower than pure pay-as-you-go billing. Some plans also restrict available models or available time windows, so coverage should be checked before choosing.

    2.4 Free Quotas and Tiered Pricing

    When a new model is launched, platforms often provide a certain amount of free Tokens. Free quotas are suitable only for early testing and should be deducted when doing long-term cost analysis. Tiered pricing lowers the unit price as monthly usage rises, so it is necessary to estimate which tier the projected usage will fall into.

    2.5 Regions and Deployment Location

    Prices for the same platform may differ across regions. Cross-region calls also add network latency and may involve data export compliance requirements. When choosing a region, price, latency, compliance, and disaster recovery capability should all be weighed.

    3. Breaking Down Bill Differences with an Example

    The following uses a set of fictional example unit prices to demonstrate the calculation method. The numbers do not represent the prices of any real platform:

    • Ordinary input: CNY 10 / million Tokens
    • Cache-hit input: CNY 1 / million Tokens
    • Output: CNY 40 / million Tokens

    Assume that in a given month, usage is 300 million input Tokens, of which 60% hit the cache, and 50 million output Tokens.

    • Ordinary input: 300 million × 40% = 120 million Tokens; cost 120 × 10 = CNY 1,200
    • Cache hits: 300 million × 60% = 180 million Tokens; cost 180 × 1 = CNY 180
    • Output: 50 million Tokens; cost 50 × 40 = CNY 2,000
    • Total: CNY 3,380

    If the same task is instead executed through batch offline processing and billed at 60% of the standard price, the total is CNY 2,028, which is 40% less than real-time calls. With the same model and the same unit price, the bill can differ substantially just through the calling method and cache design.

    The same calculation logic can be expressed in code so that actual prices can be substituted during model selection:

    1. PRICE = { # Unit: CNY per million Tokens, example values
    2. "input": 10.0,
    3. "cached_input": 1.0,
    4. "output": 40.0,
    5. }
    6. def monthly_cost(input_tokens, cache_hit_ratio, output_tokens,
    7. price=PRICE, batch_discount=1.0):
    8. cached = input_tokens * cache_hit_ratio
    9. fresh = input_tokens - cached
    10. cost = (
    11. fresh / 1e6 * price["input"]
    12. + cached / 1e6 * price["cached_input"]
    13. + output_tokens / 1e6 * price["output"]
    14. )
    15. return round(cost * batch_discount, 2)
    16. print(monthly_cost(3e8, 0.6, 5e7)) # 3380.0
    17. print(monthly_cost(3e8, 0.6, 5e7, batch_discount=0.6)) # 2028.0

    4. Designing Cache-Friendly Prompt Structure

    Cache hits require the prefix to be exactly the same. Placing stable content first and dynamic content later can improve the hit rate:

    1. [Fixed] System role definition
    2. [Fixed] Tool definitions and output format
    3. [Fixed] Knowledge base or reference documents
    4. [Dynamic] Current user question

    A common mistake is inserting a timestamp, request ID, or random example at the beginning of the system prompt. This makes the prefix different on every request, so the cache cannot hit. Logs and tracing information should be placed in other fields of the request body, not at the beginning of the prompt.

    5. Distinguishing Real-Time and Offline Tasks

    When splitting tasks, two criteria can be used: whether the user is waiting to view the result, and whether the task can accept hour-level delay.

    • Real-time tasks: chat, customer service, code completion, and similar use cases go through synchronous interfaces, with latency as the priority.
    • Offline tasks: batch summarization, data cleaning, evaluation set generation, and similar use cases go through batch interfaces, with cost control as the priority.

    In engineering, a message queue can be used to receive tasks, and batch-processing workers can periodically aggregate them for processing.