Cost Engineering Practices Behind LLM API Price Cuts

    This article breaks down how LLM API pricing is structured across regular input, cached input, and output tokens, and why a price reduction does not automatically lower your bill. It explains the technical meaning of each token category, how to design prompts and routing for higher cache hit rates and shorter outputs, and how to add budgets, quotas, and observability so cost stays under control when prices change.

    1. Starting From a Price Adjustment

    A cloud provider recently adjusted the pricing of its LLM services: the flagship tier’s input and output unit prices were both cut by roughly 20%, while cached input dropped even further, by about 60%. The lightweight tier kept the previous generation’s pricing structure, with input, cached input, and output staying around $2, $0.1, and $10 per million tokens respectively.

    For developers, what matters is not the numbers themselves but the pricing structure behind them. LLM API billing is usually split into three token categories: regular input, cached input, and output. Their unit prices often differ by one to two orders of magnitude, with cached input the cheapest and output the most expensive. This structure means the main front line of cost optimization is not “sending fewer requests,” but “making the reusable parts of a request hit the cache and compressing output length.”

    It is worth stressing that specific prices, discount levels, and caching rules change over time and across providers. Engineering practice should never hardcode any unit price into code or capacity models. Instead, treat “unit price” as a configurable item injected by a configuration center or environment variables.

    2. Pricing Logic and Technical Implications of the Three Token Types

    2.1 Regular Input Tokens

    These include the system prompt, tool definitions, conversation history, retrieved document fragments, and the current user input. They tend to be large in volume and highly repetitive. In multi-turn conversations and fixed agent workflows, the system prompt and tool definitions are often resent with every request, making them the primary source of repeated spending.

    2.2 Cached Input Tokens

    When a request prefix matches recent requests, the server can reuse the already-computed intermediate state, and these tokens are billed at a significantly lower price. This is essentially a “prefix reuse” mechanism: a hit requires the prefix to be byte-for-byte stable, and any timestamp, random ID, or dynamic ordering will invalidate the cache.

    2.3 Output Tokens

    Generated by the model, these have the highest unit price, and their cost cannot be compressed to zero. They can only be managed by controlling generation length, using structured output, and applying post-processing strategies. Generation also consumes more latency and concurrency resources, so output length is both a cost metric and a performance metric.

    3. Architectural Impact During a Price-Cut Cycle

    Lower prices do not automatically produce a lower bill. If the architecture stays unchanged, the savings from a lower unit cost are quickly consumed by growth in call volume. More commonly, a lower unit price leads teams to relax context length, add agent steps, and increase retries, so total spending actually rises.

    The right approach is to treat a price cut as a window for “redesigning the call chain”: first establish three metrics—cache hit rate, average output length, and the proportion of wasted calls—and only then evaluate whether to expand model usage.

    4. Actionable Cost Optimization Practices

    4.1 Stabilize the Prefix to Improve Cache Hits

    Split prompts into a “stable section” and a “dynamic section,” placing the stable section first with no dynamic concatenation:

    1. [System role and constraints] # Stable, unchanged over the long term
    2. [Tool and output format definitions] # Stable, version managed
    3. [Domain knowledge / retrieved fragments] # Semi-stable, updated per batch
    4. [Current user input] # Dynamic, placed last

    Engineering points: put prompts under version control; never insert the current time, a session ID, or randomly ordered results into the stable section; sort retrieval results by a fixed rule before concatenation; monitor cache invalidation, since a sudden drop in hit rate usually means the prefix has been polluted.

    4.2 Tiered Model Routing

    Classify tasks by difficulty, using the lightweight tier for classification, extraction, rewriting, and formatting, and escalating to the flagship tier only when complex reasoning is needed. The routing layer should support gradual rollout and rollback:

    1. def route(task):
    2. if task.kind in ("classify", "extract", "format"):
    3. return "model_small"
    4. if task.risk == "high" or task.steps > 3:
    5. return "model_large"
    6. return "model_small"

    4.3 Compress Output and Enforce Structure

    Explicitly limit output length and structure, and cut back on pleasantries and filler. For post-processing that can be done deterministically (parsing, validation, formatting), rely on code rather than the model. Use streaming responses to improve perceived latency and to make it easier to terminate low-value generation midway.

    4.4 Budgets, Quotas, and Circuit Breaking

    Set token budgets and alert thresholds per business line, and automatically downgrade to the lightweight model or queue requests when limits are exceeded. Apply exponential backoff to failed requests instead of retrying immediately, to avoid cost amplification during incidents.

    4.5 Observability

    For every call, record the model tier, input/cached/output token counts, hit status, latency, and business outcome, forming a cost-per-task dashboard. Without this data, no optimization can be validated.

    5. Common Pitfalls

    • Watching only unit price while ignoring hit rate and output length;
    • Concatenating dynamic content into the prefix, causing the cache to miss over the long term;
    • Using the flagship model for all tasks, including simple ones;
    • Lacking budget guardrails, so costs spiral out of control during incidents;
    • Hardcoding prices in code, making it impossible to migrate smoothly when prices change.

    6. Conclusion

    Price adjustments are an external variable; cost engineering is an internal capability. By abstracting the pricing structure into three configurable cost categories—input, cached input, and output—and building metrics and guardrails around hit rate, output length, and model tiering, you can keep bills under control despite price fluctuations. If you already use the relevant cloud product capabilities from Baidu AI Cloud, you can connect configuration, monitoring and alerting, and logging services into a unified cost governance loop that keeps optimization results continuously verifiable.