LLM API Pricing and Cost Optimization: Token Billing, Prompt Caching, and Subscription vs. Pay-as-You-Go

    A practical guide to how large language model APIs are billed: the difference between input and output tokens, the often-missed cache pricing tiers, why a larger model is not always more expensive, and how subscription plans differ from pay-as-you-go. It closes with concrete cost-reduction techniques — slimming prompts, designing cache-friendly prompts, tiered model selection, output limits, and observability.

    Why API Bills Are Getting Harder to Read

    Over the past two years, large language models have moved from technical demos to production infrastructure, and inference cost has become something engineering teams can no longer treat as an afterthought. A common pattern: for the same task, two teams can end up with bills that differ by several times. And when a new model generation launches, the per-token price sometimes rises rather than falls, which pushes teams to re-examine their calling strategy.

    To actually account for inference spend, you first need to understand the basic logic behind API billing, rather than staring at a single “price per million tokens” number.

    1. Token Billing Basics: Input, Output, and the Costs You Don’t See

    LLM APIs are typically billed by token, not per call or per unit of time. A token is the smallest unit of text the model processes: a stretch of Chinese roughly maps to a number of tokens, while an English word may be split into one or several. The bill generally has two sides:

    • Input tokens: your prompt plus the conversation history you send.
    • Output tokens: the text the model generates in response.

    Note that output tokens usually carry a noticeably higher unit price than input tokens. The reason isn’t mysterious. Generation is autoregressive: the model decodes token by token and performs a full forward pass at every step. Input, by contrast, can be processed in parallel during inference (the prefill phase), which makes compute utilization far more efficient. So when you build a cost model, don’t rely on a single blended rate — estimate input and output separately.

    A rough cost estimation sketch:

    1. def estimate_cost(input_tokens, output_tokens,
    2. price_in=0.008, price_out=0.032):
    3. # Placeholder prices per 1K tokens; illustrative only
    4. cost = (input_tokens / 1000) * price_in \
    5. + (output_tokens / 1000) * price_out
    6. return cost

    2. The Third Price Most People Miss: Cache Hits

    As context grows — long-document Q&A, repository-level code understanding, multi-turn agent interactions — a large share of input tokens is repeated content. To avoid recomputing it, the industry has widely adopted context caching, also called prompt caching. When multiple requests share the same prefix, the server can reuse the already-computed intermediate state (the KV cache) and skip a substantial amount of that work.

    In billing terms, this usually shows up as three price tiers:

    • Cache miss: the standard input price.
    • Cache hit: significantly cheaper than the standard input price, sometimes a tenth of it or less.
    • Cache write (some providers): writing to the cache for the first time may add a small amount of overhead.

    This means that even with an expensive model, if you organize stable system prompts, tool definitions, and long document prefixes into a structure that can be cached and reused, your effective input cost can drop substantially. The key factor is prefix stability: caching generally matches on token prefixes, so once the prefix content changes, everything cached after that point is invalidated.

    3. Parameter Count and Pricing: Why Bigger Isn’t Always More Expensive

    Many people assume that the larger a model’s parameter count, the higher its price. The logic seems sound, but counterexamples appear constantly in practice: a new-generation model with more parameters often costs less than the smaller model from the previous generation.

    Several things are going on:

    1. Inference engineering: more efficient attention mechanisms, better sparsity, quantization, and operator fusion all reduce the compute cost per token.
    2. Architecture and distillation: large models use knowledge distillation and sparsely activated designs such as MoE (mixture of experts), so the number of parameters actually activated at inference is far below the total parameter count. Inference cost is decoupled from total parameters.
    3. Scale effects and competition: as compute supply increases and cluster utilization improves, unit inference cost trends downward overall.

    Parameter count is therefore one dimension of capability, not a direct function of price. What really determines the per-token price is the actual compute cost of running one forward pass plus decoding on specific hardware, with the provider’s pricing strategy layered on top.

    4. Subscription Plans vs. Pay-as-You-Go: Two Different Accounting Models

    For developers, LLM services typically offer two billing models:

    • Pay-as-you-go: you pay for the input and output tokens you actually consume. This suits spiky, unpredictable, or intermittent usage.
    • Subscription / plan: you pay on a fixed cycle in exchange for a usage allowance or rate ceiling. This suits high-frequency, steady usage such as AI coding assistants.

    The nominal per-token cost of these two models often doesn’t line up. Once you convert a subscription into a per-token figure, it can look more expensive than the API. Yet a subscription user’s actual experience isn’t necessarily worse, because the plan usually bundles higher concurrency limits, more generous rate limits, and a stable context window. Conversely, even a very low API unit price leads to higher effective cost if you hit rate limits during peak hours and your throughput gets throttled.

    So when you compare options, put the following in the same table: the output-to-input price ratio, whether caching is supported and what the cache-hit price is, rate limits and concurrency allowances, the context window ceiling, and differences in quota reset cycles and settlement rules.

    5. Cost Optimization in Practice

    Once you understand the billing logic, cutting cost becomes targeted work:

    1. Slim down prompts: remove redundant instructions and repeated context. Since output tokens often cost more than input tokens, controlling response length saves money too.
    2. Design for cache friendliness: put unchanging system prompts, tool schemas, and reference material at the very front of the prompt, and put the variable parts after them, to maximize cache hit rate.
    3. Tier your model selection: use lightweight small models for simple tasks (classification, extraction, format conversion) and reserve large models for complex reasoning, instead of over-engineering every request.
    4. Stream responses and set limits: cap output length sensibly so the model doesn’t generate unnecessarily verbose output.
    5. Build observability: instrument and monitor token consumption, set alerts, break costs down by business dimension, and catch anomalous calls early.

    An example of a cache-friendly prompt layout:

    1. [System — fixed, cacheable]
    2. You are a code review assistant and follow these guidelines: ...
    3. [Tools / Schema — fixed, cacheable]
    4. Available tool definitions: ...
    5. [Context — long documents / repo snippets, kept as stable as possible]
    6. ... (keep the prefix stable)
    7. [User — the part that changes each time, placed last]
    8. Code snippet to review this time: ...

    Conclusion

    LLM API pricing is evolving from a single per-token rate into a composite structure with multiple dimensions: input, output, caching, and subscription allowances. For developers and enterprises, rather than agonizing over the absolute price of a particular model generation, it’s better to build a cost methodology based on per-dimension estimation, continuous monitoring, and scenario-based model selection. Platforms such as Baidu AI Cloud, offering both pay-as-you-go and plan-based options alongside general cloud capabilities like caching, logging, and monitoring with alerting, are the kind of infrastructure that helps teams put every unit of inference budget where it matters. What actually creates a cost gap has never been a fraction of a cent in unit price — it’s how engineered your calling strategy is.