LLM API Pricing: Cost Drivers and Model Selection Practices

    This article explains why larger models do not necessarily cost more per token, breaks inference bills down into prefill, decoding, memory, and engineering overhead, and shows how prompt caching, total-task cost accounting, and a swappable backend abstraction keep spending predictable. It also outlines a four-step selection workflow and supporting architecture practices such as tiered routing and semantic caching.

    1. The Pattern: Parameter Counts and Unit Prices Rising Together

    A pattern worth attention has emerged in the industry: a new generation of very large models has pushed parameter counts past the trillion mark while raising API unit prices several times over the previous generation. Output pricing now sits in the range of a hundred yuan per million tokens, input is roughly one fifth of output, and cached input has been compressed to a very low level. By contrast, another technical approach scaled from hundreds of billions to 1.6 trillion parameters and cut prices at the same time.

    The fact that both curves appear together shows there is no necessary causal link between “a bigger model” and “a more expensive call.” What actually determines price is the compute, memory bandwidth, and engineering amortization consumed per token, not the parameter count itself. Treating scale as the explanation for cost is the most common misjudgment in model selection.

    2. Where the Cost Comes From: Breaking the Bill into Optimizable Parts

    The cost of a single inference request breaks down into roughly four parts:

    • Prefill: a full forward pass over the input context, where compute consumption is approximately linear in input length;
    • Decoding: token-by-token autoregressive generation, constrained by memory bandwidth and the main cost driver for long outputs;
    • Memory footprint: weights plus the KV cache determine the concurrency ceiling per device, which directly affects amortized cost per token;
    • Engineering amortization: the fixed investment in batch scheduling, fault tolerance, monitoring, and operations.

    Once these four are clear, it becomes obvious why output costs more than input. Input-side computation can be highly parallelized and batched efficiently; output must advance serially, and every new token requires re-reading the entire KV cache, so bandwidth pressure is unavoidable. Cache hits are one to two orders of magnitude cheaper because they reuse an already-computed prefill result, eliminating the most expensive segment outright.

    A rough cost estimate can be written as:

    1. def estimate_cost(in_tokens, out_tokens, cached_tokens,
    2. p_in, p_out, p_cache):
    3. # All unit prices in yuan per million tokens
    4. uncached_in = max(0, in_tokens - cached_tokens)
    5. return (uncached_in * p_in
    6. + cached_tokens * p_cache
    7. + out_tokens * p_out) / 1_000_000

    The value of this function is not precision but that engineering optimizations such as restructuring prompts become quantitatively comparable.

    3. Cache Hits: The Most Underrated Lever in a High-Price Era

    When unit prices are climbing, the payoff from prompt caching is amplified. Prefixes that can be reused reliably include system instructions, tool and function definitions, coding convention documents, long documents and knowledge base excerpts, and few-shot examples. A few practices matter in engineering:

    1. The prefix must be byte-for-byte stable. Put a timestamp, a random request ID, or a username at the front and the entire cache is invalidated.
    2. Push volatile content to the end. Fixed content first, session variables last, is the basic guarantee of hit rate.
    3. Control the cache lifetime window. Schedule batch jobs together and avoid gaps that exceed the cache validity period.
    4. Evaluate with hit rate rather than unit price.
    1. [Stable prefix: system prompt + tool definitions + conventions + reference docs]
    2. [Semi-stable segment: summaries of multi-turn history]
    3. [Volatile segment: current user input]

    A quantified example: with 100,000 input tokens of which 90,000 are cache hits and 20,000 output tokens, if the hit price is only 5% of the input price, input-side spending drops by more than roughly 80%. This kind of optimization has the greatest leverage for long contexts, repository-level code understanding, and document batch processing.

    4. Subscription Quotas vs. Pay-as-You-Go: The Source of Perceived Price Gaps

    An earlier discussion raised a key insight: constrained by compute supply, subscription plan quotas are often not generous, which makes the nominal API list price closer to a “suggested retail price,” and the perceived price gap for heavy users is far smaller than the sticker gap. This holds up in engineering terms, for three reasons:

    • Separate billing pools. Chat quotas and coding quotas are often independent and cannot be shifted between each other, so the usable total is fragmented.
    • Quota reset cadence. Periodic resets make instantaneous availability fluctuate, and peak-hour queuing and rate limiting turn into hidden time costs.
    • Hidden cost items. Retries, failed requests, repeated context transmission, and repeated calls during debugging are all absent from the unit price.

    A more reasonable basis for comparison is therefore the total cost of completing the same set of tasks, not the per-token price:

    1. effective cost = (input + output + cache) charges
    2. + retry and failure losses
    3. + labor hours converted from queue waiting
    4. + engineering effort for migration and adaptation

    5. Selection Methodology: A Four-Step Decision Loop

    Step one, build a benchmark set from your own tasks. Cover the typical distribution of input and output lengths with real business samples instead of substituting public leaderboards for your own testing.

    Step two, run a length-stratified cost analysis. Bucket requests by input and output length, tally the cost of each bucket, and identify which bucket is actually draining the budget.

    Step three, make cache hit rate an acceptance metric. When the hit rate falls short of expectations, check prefix stability first rather than switching models.

    Step four, keep a replaceable abstraction layer. Wrapping model calls behind a unified interface keeps switching costs under control:

    1. class ModelBackend:
    2. def chat(self, messages, **kw): raise NotImplementedError
    3. class CachedChatBackend(ModelBackend):
    4. def __init__(self, inner, cache_prefix): ...
    5. def chat(self, messages, **kw):
    6. return self.inner.chat(self._with_prefix(messages), **kw)

    6. Architecture Support: Making Cost Control the Default

    Model unit price is an external variable; architectural efficiency is an internal one. Generally applicable measures include using object storage to hold long documents and passing them in by reference; using a message queue to smooth peaks and schedule batch jobs inside the cache validity window; using a container platform for elastic scaling to match concurrency; and using logging and monitoring with alerts to build a token-level usage dashboard with threshold alerts on abnormal growth. Baidu AI Cloud provides exactly these standard components among its general capabilities, and developers can build their own cost observability system on top of them.

    Tiered routing is another proven strategy: send simple classification, extraction, and formatting tasks to small models or a rules engine, and reserve large models for complex reasoning. Combined with a semantic cache that reuses historical results for frequent repeated questions, this can often cut a substantial share of call volume.

    7. Conclusion

    Doubling parameter counts alongside a several-fold price increase is a matter of route selection, not an industry inevitability. The right response for developers is not to wait for prices to fall but to see the cost structure clearly: use stable prefixes to raise cache hit rates, account for cost by length tier, compare options on total task cost rather than list price, and keep a unified abstraction layer that preserves room to switch. With those four in place, the impact of any pricing round on the business stays within predictable bounds.