LLM API Pricing Explained: From Per-Token Rates to Real Task-Level Cost

    LLM API pricing is often judged by headline per-token rates, but that approach ignores the input/output ratio, cache hits, and your own task structure. This article breaks down the three token categories behind LLM API billing, explains why output tokens cost more than input tokens, shows how to calculate real task-level cost from unit prices, and compares subscription plans by leverage ratio. It also covers engineering techniques that reduce spending and a three-level approach to evaluating total cost of ownership.

    Why Per-Token Price Comparisons Often Lead to Wrong Conclusions

    When using LLM APIs, a very common pattern is to look only at the sticker price — dollars per million tokens — and compare prices across vendors and model generations. When a new generation costs several times more per token than the previous one, the intuitive conclusion is “it got more expensive, so it’s not worth it.”

    This intuitive comparison has two structural flaws.

    First, per-token prices ignore the input/output ratio structure. Depending on the model and the task type, the ratio of input tokens to output tokens can differ by several times, or even dozens of times. A read-heavy, write-light summarization task and a write-heavy, read-light long-form generation task can have wildly different per-task costs, even on the same model.

    Second, per-token prices ignore the cost dilution from cache hits. Modern LLM services commonly offer a prefix caching (prompt caching) mechanism that can significantly lower billing for repeated context. As a result, there is a dynamic factor between the advertised per-token price and what you actually pay.

    To truly judge whether a model is expensive, the right methodology is to drill down from the per-token price to the task-level cost, then up to the total cost of ownership (TCO) for your business scenario over a month.

    The Three Token Categories in LLM API Billing

    Mainstream LLM APIs today charge along basically three token dimensions:

    • Input tokens (prompt tokens): the context you send to the model, including system prompts, user questions, conversation history, knowledge snippets concatenated through retrieval-augmented generation (RAG), and so on.
    • Output tokens (completion tokens): the response content the model generates.
    • Cached tokens: when the prefix of the input closely matches earlier requests, the cached portion is usually billed at a significantly lower rate than normal input — in extreme cases, as low as one-tenth of the input price or less.

    These three typically follow one basic rule: output price > input price > cache hit price.

    Understanding this structure is important because it directly determines where you should optimize. For a “large context, small output” task, focus on improving cache hit rate and trimming the input. For a “small input, large output” task, the output price is the dominant cost driver.

    Why Output Tokens Always Cost More Than Input Tokens

    This is not one vendor’s pricing strategy, but an industry-wide pattern determined by how computation works.

    During the decoding phase of autoregressive generation, the model must generate tokens serially, one at a time. Each new token’s computation depends on the hidden states of all preceding tokens (the KV Cache), so tokens cannot be processed all at once in parallel the way the input phase (the prefill phase) can. This serial dependency makes the compute utilization and parallelism of the output phase inherently lower than those of the input phase, raising the compute cost per token.

    Output token pricing also implicitly compensates for the memory and latency consumed by generating long sequences. The practical rule of thumb for users is therefore: when output tokens make up a large share of your usage, price increases have a very pronounced amplifying effect on total cost.

    The Right Approach: Calculating Task-Level Cost

    The following illustrative estimation logic shows how to derive the real cost of a task from per-token prices. All values are teaching examples and do not represent any specific vendor’s actual pricing.

    1. def estimate_task_cost(
    2. input_tokens: int,
    3. output_tokens: int,
    4. cache_hit_tokens: int,
    5. price_in: float, # price per million input tokens
    6. price_out: float, # price per million output tokens
    7. price_cache: float, # price per million cache hit tokens
    8. ) -> dict:
    9. """Estimate the real cost of a single task (sample logic; values are for demonstration)"""
    10. # Deduct cache hit tokens from normal input and bill them separately at the cache price
    11. billable_input = max(0, input_tokens - cache_hit_tokens)
    12. cost_input = billable_input / 1e6 * price_in
    13. cost_output = output_tokens / 1e6 * price_out
    14. cost_cache = cache_hit_tokens / 1e6 * price_cache
    15. total = cost_input + cost_output + cost_cache
    16. return {
    17. "Input cost": round(cost_input, 6),
    18. "Output cost": round(cost_output, 6),
    19. "Cache cost": round(cost_cache, 6),
    20. "Total task cost": round(total, 6),
    21. }
    22. # Demo: a "large-context Q&A" task
    23. result = estimate_task_cost(
    24. input_tokens=8000,
    25. output_tokens=500,
    26. cache_hit_tokens=6000,
    27. price_in=20.0,
    28. price_out=100.0,
    29. price_cache=1.0,
    30. )
    31. print(result)

    This code reveals several key insights:

    1. Cache hits are the core cost lever. The 6,000 cached tokens are billed at a very low price, compressing most of what would otherwise be an expensive input cost.
    2. Output can be the biggest cost item despite a small token count. The 500 output tokens, billed at a high price, may account for a large share of the total cost.
    3. To assess whether a model is cost-effective, you must plug in your own business’s real token distribution, rather than a single scenario a vendor highlights.

    Two Ways to Measure Real Cost

    When comparing different models or services, track both of the following:

    Measure 1: Average cost per task. Run a representative task set (for example, 20–50 real business samples), record the average input, output, and cached token consumption per task, then apply each option’s unit prices. This effectively cancels out interference from differences in task structure. Some industry evaluation approaches do horizontal comparisons this way, using average task consumption rather than simply comparing sticker prices.

    Measure 2: The ratio of a plan’s allowance to actual usage (leverage ratio). Many providers offer subscription plans. What users really care about is not the monthly fee itself, but “how much actual usage each dollar of plan fee unlocks“. If a plan costs A and covers usage worth the equivalent of B on a pay-as-you-go basis, the leverage ratio is B/A. The higher the leverage ratio, the better value a subscription plan offers.

    A rational conclusion: if a plan’s leverage ratio is clearly lower than pay-as-you-go (the plan fee doesn’t buy enough usage to pay for itself), it fails on value for money. Only when a subscription’s leverage ratio reaches several times, or even more than ten times, pay-as-you-go does it truly become competitive with premium foreign models.

    Cost Optimization in Engineering Practice

    Whether you use a large-model service platform such as Baidu AI Cloud or a general-purpose approach in the industry, these optimization techniques apply:

    • Improve the cache hit rate: Put stable system prompts and fixed knowledge prefixes at the very front of the request so the prefix stays completely identical and prefix caching takes effect; place user input that changes on every request at the end.
    • Trim and compress context: Reduce unnecessary input tokens through summarization, retrieval reranking, deduplication, and similar techniques, especially for long-document scenarios.
    • Control output length: Use explicit output format constraints and a max token limit to prevent runaway output costs from an overly verbose model.
    • Tiered routing: Route simple tasks to lightweight small models and reserve large-parameter models for complex tasks, reducing overall cost through model tiering.
    • Build cost observability: Use logging services and monitoring alerts to track token consumption and costs by business dimension, create a cost dashboard, and detect abnormal consumption promptly.
    • Use a mixed billing strategy: Use subscription plans to spread costs across high-frequency, stable scenarios, with pay-as-you-go as a fallback for traffic spikes.