Understanding LLM API Pricing: A Breakdown of Token Billing, Cache Hits, and Cost Control

    A practical breakdown of how large language model API pricing works, covering input, output, and cache-hit token billing, prefix caching rules, pay-as-you-go versus subscription quotas, and engineering practices such as output control, context compression, model routing, and observability to keep costs predictable after a price change.

    1. The Signal: Why One Price Change Sparked Broad Debate

    A flagship large language model recently raised its public API prices noticeably: output pricing is roughly five times the previous generation, while input and cache-hit pricing were adjusted as well, producing a three-tier structure of “high output, medium input, low cache.” The debate is not really about the increase itself. It is about the fact that a change in price structure directly changes an application’s cost curve: a product that was profitable under the old prices may become loss-making under the new ones.

    One point should be clear up front: this article does not evaluate any specific vendor’s pricing strategy and does not recommend any product. Prices and rules should always be confirmed on the official pages, and any numbers below are illustrative of magnitude only, used to explain how to analyze a billing model. For developers, only three questions genuinely matter: where the money goes, which costs are controllable, and how to convert uncontrollable costs into controllable ones at the architecture level.

    2. Decomposing the Billing Basis: How One Request Is Split into Chargeable Segments

    Billing for mainstream LLM APIs is fundamentally organized around tokens, but a single request is typically split into three separately priced categories:

    • Input tokens: prompts, system instructions, conversation history, retrieved documents, code repository snippets, and everything else sent to the model.
    • Output tokens: generated content, including reasoning traces (if enabled) and the final answer.
    • Cache-hit tokens: the portion that exactly matches a previous request prefix and is reused server-side, usually priced well below normal input.

    A schematic billing formula looks like this:

    1. Cost per request = input tokens × input price
    2. + output tokens × output price
    3. + cache-hit tokens × cache price

    The most important detail here is that the output price is usually several times the input price. Generation requires token-by-token forward computation and cannot be parallelized in a single pass the way input processing can, so compute density is higher. That is why a fivefold output increase affects cost far more than an equivalent increase on the input side.

    3. Why Vendors Keep Cache Pricing So Low

    Cache hits are cheap because the server trades repeated computation for storage and lookup. Prefix caching requires the token sequence to match exactly from the beginning; any change in the middle causes everything after the change point to fall back to standard input billing.

    Several engineering conclusions follow:

    1. Prioritize stability: put system prompts, tool definitions, and output format constraints at the front, and avoid changing them frequently.
    2. Push variables to the end: place user input, timestamps, random IDs, and retrieved results at the tail of the prompt so the prefix stays clean.
    3. Batch and order consistently: keep the same context organization order for similar requests to raise the hit rate.

    A counter-example:

    1. [timestamp 2026-08-20 10:00:00] ← changes every time, so nothing after it can hit
    2. [system instructions ...]
    3. [user question ...]

    Reordered:

    1. [system instructions ...]
    2. [tool and format constraints ...]
    3. [user question ...]
    4. [timestamp 2026-08-20 10:00:00]

    Reordering alone can produce a meaningful cost difference in high-frequency calling scenarios.

    4. Subscription Quotas vs. Pay-As-You-Go: Different Cost Structures

    Beyond metered APIs, “coding subscription plans” are also common: a fixed monthly fee buys a quota expressed in credits or token equivalents, usually across several tiers, with a lower unit price at higher tiers. The difference between the two models can be abstracted as:

    • Pay-as-you-go: cost grows linearly with usage and fluctuates, but there is no fixed spend; suited to unpredictable traffic and elastic scaling.
    • Subscription quota: converts variable cost into fixed cost and lowers the unit price by tier, but carries the risk of wasted quota and overage penalties.

    The decision method is not complicated. A rough break-even estimate:

    1. If average monthly metered cost > monthly subscription fee × 0.7, the subscription is usually better value
    2. If average monthly metered cost < monthly subscription fee × 0.3, pay-as-you-go is more flexible
    3. In between, weigh usage volatility and quota carry-over rules

    Note that plans differ substantially in how quota is deducted: some convert input and output separately, some price cache hits separately, and some apply an extra multiplier to reasoning-heavy tasks. Read the full billing rules before choosing, rather than comparing monthly fees alone.

    5. Engineering Practices for Cost Optimization

    After a change in price structure, the controllable parts concentrate in three places: reduce output, compress input, and raise the cache hit rate.

    1. Control output length. Require structured output, limit the number of fields, avoid having the model restate the input, and for long-text tasks generate in segments and merge.
    2. Compress input context. In RAG scenarios, rerank and truncate first, keeping only genuinely relevant fragments; for code repositories, retrieve along the call chain instead of stuffing in whole files.
    3. Stabilize the prefix. Move invariant content to the front and version it; route prompt changes through a release process so an ad hoc edit does not break the cache.
    4. Tiered routing. Send simple tasks to smaller or local models and escalate complex ones to the flagship model; this is the highest-return optimization.
    5. Observability. Feed token usage, cache hit rate, and per-request cost into logging and monitoring with budget threshold alerts, so cost governance has a basis.

    Schematic routing logic:

    1. def route(task):
    2. if task.difficulty <= 1 and task.max_output < 500:
    3. return "small_model"
    4. if task.need_long_context:
    5. return "long_context_model"
    6. return "flagship_model"

    6. An Enterprise Selection Checklist

    In response to a price change, evaluate in this order: first define hard requirements for latency, context length, multimodality, and stability; then run a small-percentage canary on real traffic and measure the input/output ratio and cache hit rate; finally write budget constraints into the architecture instead of patching things after the bill arrives. For a hybrid architecture, keep high-frequency, low-difficulty requests on self-hosted inference and send complex requests to cloud general-purpose model capabilities, using common cloud products such as object storage and message queues for layered data and task management.

    The takeaway: price structure matters more than the price number. Understanding three-tier input, output, and cache billing, and treating cache hit rate and output length as optimizable engineering metrics, is what keeps costs under control when prices move.