Cost Engineering for LLM APIs: Why Stable Pricing Doesn't Mean Stable Bills

    This article explains why unchanged API unit prices can still lead to higher bills after a model upgrade, and how engineering teams can measure and control the real cost. It breaks down the cost formula, highlights four key variables such as input-output price asymmetry, prefix caching, per-task cost, and output inflation, and presents a reusable task-level cost measurement method. It also lists five practical cost-reduction techniques and offers model selection advice based on cost per passing task rather than benchmark scores or token prices alone.

    1. The Phenomenon: Unit Price Stays the Same, the Bill Does Not

    A common pattern is emerging in the industry: a new-generation model shows a clear improvement in overall capability scores, while the official API prices for input, output, and cached input tokens remain at the previous generation’s level. On the surface, this looks like “more capability at the same price.” From an engineering billing perspective, however, that conclusion does not hold.

    To understand why, start by expressing the cost of a single call in a computable form:

    1. cost per call = input tokens × input price
    2. + output tokens × output price
    3. + uncached input tokens × input price
    4. + cached input tokens × cache price

    Unit price is only a coefficient in this formula. What actually determines the bill are three variables: how many rounds of calls a task is split into, how much context is packed into each round, and how many output tokens the model emits to complete the task. When a new-generation model “thinks more thoroughly,” an increase in output tokens is a common result. A rise of roughly 20% is enough to offset the psychological comfort of unchanged unit prices.

    So when evaluating a model upgrade, the right unit of measurement is not “dollars per million tokens,” but “dollars per accepted task.”

    2. Four Key Variables

    2.1 Input and Output Prices Are Asymmetric

    Output prices on mainstream inference services are typically several times the input price, because autoregressive decoding cannot be parallelized as heavily as prefill. This leads to a core optimization principle: any technique that reduces output length yields a higher return than compressing the input by the same proportion.

    2.2 Structural Discounts from Cache Hits

    When the input side supports prefix caching, the cached portion can be billed at around 20% of the original price, close to a 20% discount. But the benefit depends entirely on prefix stability: the system prompt, tool definitions, and few-shot examples must sit at the very front and remain byte-for-byte identical. Timestamps, random IDs, and retrieval results should come later.

    A counter-example shows how serious the problem is:

    1. # Bad pattern: volatile content placed in the prefix
    2. system: current time 2026-08-12 10:33:07 ...
    3. tools: [...]
    4. # The time differs on every request → prefix hash changes → the entire cache is invalidated

    2.3 Cost per Task Is the Comparable Metric

    At the same intelligence tier, different models can differ by more than 20% in the cost of completing the same batch of tasks. The differences come from default reasoning depth, number of tool-call rounds, and failure retry rates. Comparing unit prices alone leads to a completely wrong procurement conclusion.

    2.4 The Hidden Bill of Output Inflation

    A 20% rise in output tokens is amplified in long-horizon agent scenarios: the tool result of each round becomes the input of the next round, creating a multiplier effect where output drives input.

    3. A Reusable Cost Measurement Method

    Teams should build a task-level cost table with fields including: task ID, number of call rounds, input/output/cache-hit tokens, number of failed retries, cost per task, and acceptance pass rate. During evaluation, fix the same task set and the same acceptance script, and change only the model version, so the comparison is trustworthy.

    Pseudocode:

    1. def task_cost(trace, price):
    2. p_in, p_out, p_cache = price
    3. return (
    4. trace.input_tokens * p_in
    5. + trace.output_tokens * p_out
    6. + trace.cache_hit_tokens * p_cache
    7. )
    8. # Key: use "tasks that passed acceptance" as the denominator
    9. unit_cost = total_cost / passed_tasks

    Setting the denominator to the number of passing tasks rather than the number of calls automatically folds retry and failure costs into the metric, avoiding the illusion of “cheaper unit price but repeated retries.”

    4. Five Cost-Reduction Techniques

    1. Layer the context: stable prefix (role, guidelines, tool schema) + semi-stable middle (project structure notes) + volatile tail (user input, retrieval snippets), to maximize cache hits.
    2. Constrain the output budget: state the format and length limits explicitly in the prompt, require the conclusion first and details after, and avoid lengthy restatement.
    3. Prefer structured output: constrain responses with a JSON Schema to reduce natural-language redundancy and retries caused by parsing failures.
    4. Tiered routing: send simple steps such as intent recognition and format validation to small models or a rules engine, and reserve complex reasoning for the flagship model.
    5. Close the observability loop: connect logging services and monitoring alerts, and set threshold alerts on token consumption, cache hit rate, and cost per task, so cost anomalies surface within hours rather than at month end.

    5. Selection Advice

    At the same capability tier, make a two-dimensional decision based on “cost per task + acceptance pass rate” rather than leaderboard scores alone. If an option involves open weights, also evaluate the compute depreciation and operational overhead of private deployment, convert them into cost per task, and then compare. In addition, keep an abstraction layer that wraps model calls behind a unified gateway, so switching costs stay controllable.

    6. Conclusion

    When a capability upgrade and unchanged prices appear together, what really deserves attention is the hidden spending from output inflation and more call rounds. Switching the unit of measurement from token unit price to cost per task, combined with cache-friendly design, output budgets, and tiered routing, is what delivers a deterministic cost advantage at the same intelligence tier. The focus of the next stage of competition is no longer just scores, but unit cost efficiency at the same level of intelligence.