LLM Cost Reduction Guide: How to Cut Token Spend with Prefix Caching and Model Tiering

    Rising LLM bills usually trigger a switch of vendors, but the faster win is to break the bill down first. This guide explains how per-call cost is made up of input tokens, output tokens, and whether the prefix cache is hit, and why the real lever is the effective utilization of billed tokens rather than unit price. It covers four mechanisms: keeping a stable prefix to make repeated context free, splitting work across planning, execution, and review tiers so each model matches its capability-to-cost ratio, sizing token packages by effective rather than nominal volume, and using free tiers for repeatable benchmarks. It also lists the observability metrics required to sustain savings and a practical rollout checklist.

    1. Where the Cost Pressure Comes From: Read the Bill Structure First

    When LLM-related costs start climbing, many teams’ first instinct is to switch providers. A more effective move is to decompose the bill. The cost of a single call is typically made up of three parts: input tokens, output tokens, and whether the prefix cache is hit. The input side is often underestimated—in intelligent coding and long-document processing scenarios, system prompts, repository context, and conversation history get carried along repeatedly, so input volume is often several times the output volume.

    This leads to a key conclusion: the main battlefield for cost reduction is not the “unit price” but the effective utilization of billed tokens. If more than 90% of the prefix in a request is identical to the previous one, that content should not be billed again on an inference service that supports caching. Understanding this is what gives the optimization strategies that follow a place to land.

    2. Mechanism 1: Prefix Cache Hits Turn Repeated Context into Zero Cost

    Mainstream inference services generally support prefix caching: when the token sequence prefix of a request is exactly the same as a recent request, that portion can reuse the already-computed intermediate state, cutting or even eliminating the charge. To raise the hit rate in practice, three disciplines apply:

    1. Put the stable prefix first. Place the system prompt, tool definitions, and long-lived conventions at the front, and volatile content (timestamps, random IDs, the user’s current-turn input) at the end.
    2. Avoid prefix jitter. Do not concatenate the current time, a request ID, or a randomly ordered candidate list into the system prompt—these “tiny changes” invalidate the entire prefix.
    3. Keep append-only within a session. In multi-turn conversations, only append to the tail; do not rewrite history messages, or the cache chain breaks.

    A schematic structure looks like this:

    1. [stable layer] system role + output spec + tool/function definitions + project conventions
    2. [semi-stable layer] repository summary, interface list, dependency notes
    3. [volatile layer] current user instruction, temporary variables, timestamps

    An often-overlooked detail: caches usually have a time-to-live window and limited capacity. High-concurrency, long-interval call patterns significantly reduce the hit rate. Batching similar tasks together improves hit rate and throughput at the same time.

    3. Mechanism 2: Layered Orchestration Lets Different Capability Tiers Do Their Own Job

    Having a single model handle all the work is a common cause of runaway cost. The more economical approach is to split tasks into three types and assign them to models with a better capability-to-cost ratio:

    • Planning tier: needs strong reasoning and a global view; breaks down goals, defines interfaces, and sets acceptance criteria. Low call volume, high value.
    • Execution tier: handles bulk code generation, rewriting, and test completion. Highest call volume, so it should use a cost-effective model and be given sufficiently explicit instructions.
    • Review tier: handles review, regression verification, and fallback correction, with a controllable sampling volume.

    The “weak proactive execution” behavior mentioned in the original text can be described, in a general context, as a model characteristic: the model tends to follow instructions strictly rather than proactively filling in implicit intent. This is not a defect but an orchestrable interface trait—as long as the upstream plans the steps at a fine enough granularity, the execution tier’s output stability is actually higher.

    1. def solve(task):
    2. plan = planner.run(system=STABLE_PROMPT, user=task) # strong reasoning, few calls
    3. patch = executor.run(system=STABLE_PROMPT, user=plan) # high throughput, many calls
    4. report = reviewer.run(system=STABLE_PROMPT, user=(task, patch))
    5. return report if report.passed else planner.run(user=report.feedback)

    Note that STABLE_PROMPT stays consistent across the three tiers. This is both a quality constraint and a cache-friendly practice.

    4. Mechanism 3: The Limits of Token Packages and Procurement Strategy

    Token-based resource packages usually have a better unit price than pay-as-you-go, but you must account for “effective tokens” rather than “nominal tokens.” The formula simplifies to:

    1. effective capacity ≈ nominal quota ÷ (1 - cache hit rate)

    If the hit rate stays around 95%, the nominal quota needs to be scaled up by 10–20x to approach the real usable amount. So before purchasing, run a small-sample load test with real business traffic, measure the hit rate distribution, and then choose the tier. Team-level procurement also needs to consider quota validity periods, concurrency limits, and overage policies, to avoid “buying a lot and not using it.”

    5. Mechanism 4: Using Free Quotas and Trial Channels Correctly

    Most cloud platforms and intelligent coding tools offer free quotas or trial channels, which suit three things: validating prompt stability, measuring the cache hit rate, and evaluating a model’s pass rate on your own codebase. It is best to spend free quota on “repeatable benchmark evaluation” rather than daily production traffic—this stays compliant and produces comparable data.

    6. Observability: No Measurement, No Cost Reduction

    Cost reduction has to be built on measurement. At minimum, collect these metrics: input/output token distribution, cache hit rate, average call rounds per task, task first-pass rate, and cost per unit of effective output. If you use relevant Baidu AI Cloud capabilities, you can combine log services with monitoring and alerting to build a dashboard, and set threshold alerts for hit rate and failed retries—retries are an invisible cost amplifier, and three rounds of retry after one failure often cost more than the original call.

    7. Rollout Checklist

    1. Restructure prompt layering, put the stable prefix on top, and remove jitter sources such as timestamps.
    2. Switch multi-turn sessions to append-only, avoiding history rewrites.
    3. Build a three-stage planning–execution–review pipeline, assigning models by capability.
    4. Measure the hit rate with a small sample of real traffic, then size the resource package tier.
    5. Build a cost dashboard with cache hit rate and first-pass rate as core metrics.
    6. Set caps and fallback paths for failed retries to prevent runaway cost.

    Following this path, most teams can cut the cost per effective token by an order of magnitude while preserving output quality—the key to cost reduction is not finding a cheaper model, but making every call repeat as little computation as possible.