How to Cut LLM API Costs When Token Prices Stay Flat but Bills Keep Rising

    This article explains why unchanged token pricing can still lead to higher bills as newer models consume more output tokens, and presents a four-dimension evaluation framework covering token price, cache hit rate, cost per task, and effective intelligence density. It details four engineering techniques to reduce spending—prefix stabilization, output constraints, tiered routing, and budget guardrails for long-running agents—plus the observability metrics needed to locate cost issues. Readers will find a practical, rollback-safe rollout sequence for model selection and cost governance.

    1. The Phenomenon: Flat Unit Prices, Higher Bills

    A product pattern worth watching has emerged in the industry: a new generation of general-purpose LLMs has jumped from 53 to 60 on the public evaluation intelligence index, matching competitors in the same tier, while API token prices remain identical to the previous generation—about $1.40 per million input tokens, $4.40 per million output tokens, and $0.26 per million cached input tokens (roughly an 81% discount on the hit portion). The official evaluation also reports a per-task cost of about $0.68, lower than the same-tier competitor’s ~$0.84 and the higher-priced model’s ~$1.23.

    But the same dataset contains a counter-signal: completing the same task consumes about 20% more output tokens than the previous generation. “Unchanged unit price” does not mean “unchanged total spend.” The cost formula makes this clear:

    1. Total task cost = input_tokens × input_price
    2. + output_tokens × output_price
    3. + (input_tokens - cached_tokens) × input_price × (1 - discount_rate)

    Unit price is one multiplier; usage is another. When output usage rises 20% and output price is more than three times the input price, output-side inflation is amplified enough to erase the benefit of flat pricing. To judge whether a model is “cheaper,” you must look at cost per task, not the price list.

    2. A Four-Dimension Evaluation Framework: Look Beyond the Price List

    1. Token unit price: sets the baseline, not the outcome

    Unit price determines the slope of the cost curve—necessary but far from sufficient. Price differences between same-tier models are usually within a small multiple, while usage differences can reach several times.

    2. Cache hit rate: the most overlooked discount lever

    Cached input pricing is roughly 18% of the standard input price, and a high hit rate can significantly cut input costs in long-context scenarios. But cache hits are not free: they require a byte-for-byte stable prefix. Any timestamp, random ID, or dynamic ordering invalidates the entire prefix.

    3. Cost per task: the only metric that aligns with business budgets

    Only “how much it costs to complete one acceptance-ready task” can enter a financial model. Build your own benchmark set with fixed tasks and a fixed acceptance script rather than quoting vendor marketing figures.

    4. Effective intelligence density: usable capability per dollar

    Defined as task pass rate per unit cost. A 7-point intelligence gain that costs 20% more output tokens means the token cost per point of intelligence has risen; cost-sensitive businesses must weigh this explicitly during selection.

    3. Four Engineering Techniques to Bring Costs Down

    Technique 1: Stabilize the prefix to raise the cache hit rate

    Place and freeze the common part of all requests at the front, and put dynamic content at the end:

    1. SYSTEM = "You are a code review assistant. Rules: 1) output only the issue list 2) each item includes file and line number ..." # frozen; never concatenate timestamps
    2. def build_messages(repo_ctx: str, user_q: str):
    3. return [
    4. {"role": "system", "content": SYSTEM}, # stable prefix, cache-friendly
    5. {"role": "user", "content": repo_ctx}, # semi-stable context
    6. {"role": "user", "content": f"[{user_q}]"}, # dynamic tail
    7. ]

    Supporting rules: concatenate repository context in lexicographic file-path order; never insert UUIDs, current time, or retry counts into the prefix; bump the template version uniformly on changes to avoid mixing old and new prefixes and causing hit-rate jitter.

    Technique 2: Constrain output length to cut the most expensive multiplier

    Output has the highest unit price, and “smarter” models tend to be more verbose. Use structured output to say just enough:

    1. schema = {
    2. "type": "object",
    3. "properties": {
    4. "issues": {"type": "array", "items": {
    5. "type": "object",
    6. "properties": {"file": {"type": "string"}, "line": {"type": "integer"},
    7. "severity": {"type": "string"}, "fix": {"type": "string"}},
    8. "required": ["file", "line", "severity", "fix"]}},
    9. "summary": {"type": "string", "maxLength": 200}
    10. },
    11. "required": ["issues", "summary"]
    12. }
    13. # combine with a max_output_tokens cap + a plan-then-fill prompting strategy to suppress redundant reasoning text

    Technique 3: Tiered routing so expensive models handle only hard problems

    First classify intent with a small model or rules, then decide whether to escalate:

    1. def route(task):
    2. if task.risk == "low" and task.est_tokens < 2000:
    3. return "small_model" # low-cost tier
    4. if task.type in ("code", "agent_long_horizon"):
    5. return "flagship_model" # high-capability tier
    6. return "mid_model"

    Routing gains come from the distribution, not the average: when most requests land in the low-cost tier, the overall bill drops far more than the extra cost of a few hard problems.

    Technique 4: Budget guardrails for long-horizon agent tasks

    Agent task cost is “steps × tokens per step” and is the easiest to lose control of. Set hard constraints:

    1. agent_budget:
    2. max_steps: 12
    3. max_total_tokens: 120000
    4. max_output_ratio: 0.35 # trigger compression when output share exceeds the threshold
    5. on_exceed: summarize_and_stop
    6. checkpoint_every: 3 # persist intermediate state for resume, avoiding repeated spend

    4. Observability: No Measurement, No Optimization

    Cost governance starts with breaking the bill down to request granularity. Instrument uniformly at the gateway layer and record at least: cached input tokens, input/output tokens, routing tier, task ID, and retry count. These fields let you compute true cost per task and locate anomalies:

    1. if cache_hit_ratio < 0.3 and input_tokens > 8000:
    2. alert("Unstable prefix; cache benefit is leaking")
    3. if output_tokens / input_tokens > 0.6:
    4. alert("Output inflation; check prompts and structured constraints")

    Pair this with log services and monitoring alerts to build trend dashboards, and drill down across three dimensions—business line, model tier, and task type—to turn “it feels more expensive” into a specific, locatable step.

    5. Selection Conclusions and Rollout Order

    Facing a new generation of models with “higher capability, flat unit price, higher usage,” the rational approach is not a binary switch-or-stay choice, but turning selection into a rollback-safe engineering decision:

    1. Build a benchmark set of 50–100 real tasks, measure pass rate and cost per task, and form your own four-dimension scorecard;
    2. Use stable prefixes + structured output to reduce usage first, then evaluate the new model, avoiding misjudging “usage inflation” as “a more expensive model”;
    3. Roll out tiered routing and budget guardrails to keep cost variance within a predictable range;
    4. Maintain a multi-provider abstraction layer with a unified gateway interface so models are pluggable, canary-releasable, and rollback-ready.

    The next phase of competition has shifted from “whose score is higher” to “who can push cost per task lower at equal intelligence.” For developers, the real moat is not picking a particular model, but having a measurement and scheduling system that converts intelligence density into a cost advantage. If you host the gateway, cache, and monitoring chain on Baidu AI Cloud’s model services and container platform, you can bring model calls, logs, and alerts under unified management and keep iterating on your cost baseline.