Behind LLM API Price Increases: Cache Economics in the Agent Era

    This article explains how the input and output price tiers of LLM APIs affect the cost of Agent workloads. It covers how cache hit rate, input-to-output token ratios, and retry rates change the cost per successful task, and it lists engineering practices for reducing those costs.

    1. Set Aside the Multiplier and Establish a Common Cost Baseline First

    LLM API price lists usually include at least three unit prices: uncached input, cached input, and output. In chat scenarios, requests tend to have short context and few turns, so price differences mostly show up as small changes in the total bill. For Agents, code generation, repository-level understanding, and long document review, a single task may involve thousands of tool calls and hundreds of thousands of tokens or more in rolling context. In these cases, the pricing structure directly affects whether a task is feasible.

    Before discussing how much more expensive a model is, you need to put costs on the same denominator. There are three common denominators:

    • Cost per million input tokens: useful for estimating the cost of retrieval, reading, and loading context.
    • Cost per million output tokens: useful for estimating the cost of generation, rewriting, and code completion.
    • Cost per successful task: the most useful measure for Agent workloads, because the business cares how much it costs to deliver a result, not the unit price of one direction.

    Use the following general formulas as a starting point:

    1. Effective input price = h * P_hit + (1 - h) * P_miss
    2. Task cost = N_in * Effective input price + N_out * P_out
    3. Cost per output = r * Effective input price + P_out
    4. where r = N_in / N_out, and h is the cache hit rate

    These formulas break a price increase into three variables you can manage. r is how much context you feed into the model. h is how well you reuse prefixes. P_out is how expensive generation itself is. Suppose a newer model raises the output tier and sets a very low price for cached input. The overall price goes up, but the pricing also encourages a specific way of working: keep system prompts stable, reuse long prefixes, avoid sending the same content repeatedly, and control unnecessary output.

    2. Why Output Prices Rise the Most Sharply

    From the perspective of inference systems, input and output costs are not symmetric. Input processing happens mainly in the prefill stage. It is highly parallel, can be batched, and can reuse cached long prefixes. Output happens in the decode stage, which generates one token at a time. Decode depends heavily on memory bandwidth, KV Cache reads and writes, and continuous scheduling, and it cannot be parallelized as easily as prefill. Longer context means decode must maintain a larger attention state, so every generation step consumes a steady and ongoing amount of resources.

    This means that when a model becomes more capable, average context grows, and an Agent task takes more steps, output tokens are no longer just a longer answer. They tie directly to longer residence time, higher memory pressure, and more complex scheduling. Raising the output price is, in essence, a way to recover pricing power over scarce decode resources.

    Input follows a different logic. Uncached input requires a full prefill, which is expensive. Cached input that hits a prefix cache skips much of the repeated computation, which is cheap. Providers therefore widen the gap between hit and miss prices to push users toward stable prefixes, session affinity, and layered context. For the platform, this improves cluster utilization. For customers, it means engineering teams must treat caching as a core design concern, not an optional optimization.

    3. Two Customer Types May Face Very Different Actual Costs

    This is an illustrative arithmetic example that does not correspond to any specific product. Assume the output price is much higher than the input price, the cached input price is very low, and the uncached input price is relatively high.

    Enterprise coding Agents often have stable system prompts, fixed tool descriptions, and repeated project background. Their input can far exceed their output, with an input-to-output ratio of about 20:1. If the cache hit rate stays near 90%, the effective input price is substantially diluted. In that case, even with a high output price, the total cost per completed task can remain manageable.

    Individual developers or occasional explorers look different. Their prompts change every time, they paste large blocks of context on the fly, prefix reuse is weak, the input-to-output ratio may be only about 5:1, and the hit rate might be around 20%. The same list price results in a higher effective input cost and weaker cache benefit for this usage pattern. Two users looking at the same price list can experience costs that differ several times over.

    This is the difference between a nominal price increase and an effective one. For long tasks with heavily reused prefixes, the increase falls mainly on output. For short tasks with fragmented context, the increase affects both uncached input and output. Enterprises should ask not whether unit prices went up, but which traffic pattern their workload resembles.

    4. Why the Agent Era Amplifies Price Sensitivity

    In traditional conversations, a single interaction ranges from tens to thousands of tokens, so users rarely notice unit prices. Agents turn model calls into a loop: plan, call a tool, read the result, reflect, and plan again. One task can consume hundreds or thousands of model calls. Long context is re-sent at every step, so any change in the prompt can break the prefix cache, and any redundant output gets multiplied by the number of steps.

    Code scenarios are a clear example. System prompts, tool schemas, repository maps, interface constraints, and testing standards are highly stable, so they naturally belong in a reusable prefix. What changes frequently includes the current file fragment, failure logs, diffs, and the user’s latest instruction. If an implementation mixes stable and changing content together, the cache hit rate drops quickly, and the team effectively gives up the lower price tier.

    Therefore, optimizing Agent costs is not simply about asking fewer questions. It requires redesigning the context lifecycle. Decide what stays in the persistent prefix, what should be retrieved on demand, what should be summarized and written back, and what should never enter the context. The more the price list differentiates between tiers, the more this layering pays off.

    5. The Real Resource Cost of Sparse Models and Long Context

    Newer flagship models generally tend toward larger sparse expert architectures. They have a very large total parameter count, but activate only a few experts per token to limit computation. However, “few active parameters” does not mean “cheap to deploy.” Weights must stay resident or be quickly schedulable. Expert routing introduces cross-device communication, popular experts can cause load imbalance, and long context adds pressure on KV Cache capacity and bandwidth. Introducing hybrid attention, long-range state compression, or more complex kernel strategies raises the bar for engineering optimization even further.

    Consumers cannot directly see these low-level details, but they affect prices in three ways. First, long context no longer suits coarse pricing. Second, stable prefixes and high cache hit rates become the core path to lower costs. Third, the marginal cost of output tokens is more sensitive, because decode is hard to amortize. Understanding this helps avoid reading a price list as simply a vendor trying to charge more. The list reflects resource constraints, utilization goals, and traffic shaping.

    6. An Engineering Checklist for Cost Optimization

    1. Stabilize the prefix: Place system instructions, tool definitions, code standards, and domain constraints in a fixed header. Avoid inserting timestamps, unrelated examples, or dynamic IDs at random.
    2. Layer the context: Separate content that is permanently valid, valid for the session, and valid for a single step. Keep only the minimum necessary changes in the tail.
    3. Route with session affinity: Send requests from the same task to instances that can reuse the prefix, which reduces cold-start prefill.
    4. Trim tool results: Compress, extract, and summarize raw logs before feeding them back to the model. Avoid repeatedly stuffing full stack traces into the context.
    5. Set output budgets: Define maximum output lengths and stop conditions for planning, code, and summaries, so reflection loops cannot generate indefinitely.
    6. Meter costs per task: Aggregate tokens, steps, hit rates, and failed retries for each task, rather than counting only API calls.
    7. Route across model tiers: Send simple classification to a lower-cost tier and complex reasoning to a higher tier. Use routing instead of one model for everything.
    8. Build a regression baseline: Fix a set of representative tasks and track cost per successful task, hit rate, and latency. Replay them before upgrading models.

    A minimal cost estimator might look like this:

    1. def cost(n_in, n_out, p_miss, p_hit, p_out, hit_rate):
    2. eff_in = hit_rate * p_hit + (1 - hit_rate) * p_miss
    3. return n_in * eff_in + n_out * p_out
    4. def per_success(calls, retry=0.0):
    5. return sum(calls) * (1 + retry)

    The code itself matters less than tracking hit_rate, the input-to-output ratio, and the retry rate in one dashboard. Without these three metrics, any cost-saving technique is guesswork.

    7. Putting It on a Cloud Platform: Cost Governance with General-Purpose Services

    Enterprises that want to productize these strategies can build a closed loop with general-purpose cloud services from Baidu AI Cloud. Object storage can hold prompt versions, context snapshots, and task samples. Message queues can decouple tool execution from model calls, smooth traffic peaks, and support replay. A container platform can run routing logic, caching policies, and evaluation jobs. Log services and monitoring with alerting can report hit rates, token distribution, output length, retry rates, and cost per task. The focus here is on general service categories and governance practices, not on any particular external model or third-party interface.

    Keep the boundaries in mind. Cost optimization should not mean circumventing limits or consuming resources unfairly. Do not promise that a given workload will get cheaper before validating it. The right approach is to establish a baseline, run small-traffic experiments, select model tiers based on business SLAs, and reduce unnecessary context and output only while quality metrics stay stable.

    8. Conclusion: The Price List Is Becoming an Architecture Blueprint

    When output becomes more expensive, cached input becomes cheaper, and uncached input becomes more expensive, the price list stops being only a purchasing document. It becomes an architecture blueprint. It rewards stable prefixes, penalizes random context, rewards short and precise output, penalizes long reflection, and rewards sustainable Agent engineering over one-off scripts. Teams that still call models the way they did in the chat era will find costs out of control. Teams that rebuild context, caching, and metering for the Agent era can turn unit price changes into predictable engineering leverage. Long-term competitiveness comes from making every token serve a successful task, through observable, replayable, and governable systems, not from finding the cheapest model.