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

    This article explains why unchanged API unit prices can still lead to higher costs after a model upgrade, and how to evaluate upgrades by cost per task rather than by the price list. It covers four metrics to assess together—overall intelligence, pricing structure, cost per task, and output token inflation—along with a reusable cost estimation script and six engineering techniques for cost optimization, including prefix-cache-friendly prompts, output constraints, tiered routing, batching, semantic caching, and observability. It also offers model selection guidance for long-context, multi-turn, and structured-output workloads.

    1. The Phenomenon: Fixed Unit Prices Do Not Mean Fixed Bills

    A common pattern in the industry is a new-generation model release with clearly higher benchmark scores, while the official API prices for input, output, and cached input tokens stay the same as the previous generation. On the surface, this looks like pure upside. From an engineering billing perspective, however, only one of four variables has been held constant.

    The actual cost of a single call can be approximated as:

    1. cost per call = input tokens × input price
    2. + output tokens × output price
    3. - cached input tokens × (input price - cache price)

    Unchanged unit prices only lock the coefficients. What really drives spending is the number of tokens, especially output tokens. When stronger capabilities come with longer reasoning and more complete responses, natural growth on the output side can cancel out the unit-price benefit. So evaluating whether a model upgrade is “cheaper” requires looking at cost per task, not the price list.

    2. Four Metrics to Evaluate Together

    2.1 Overall Intelligence

    A common industry practice is to score models horizontally with a unified benchmark index. A jump from the low fifties in the previous generation to the sixty range signals a cross-generation improvement, and it also means the model now competes head-to-head with other options in the same tier. A score only shows whether a task can be done correctly, not how much it costs to do so.

    2.2 Pricing Structure

    Typical tiered pricing has four components: input, output, cached input, and regular input when the cache is not hit. Cached input usually receives a significant discount (in the original scenario, roughly a little over twenty percent of the regular input price, equivalent to more than a twenty percent discount). This is highly beneficial for long-context workloads, fixed system prompts, and multi-turn repeated prefixes.

    2.3 Cost per Task

    Using “completing one real task” as the unit of measurement is closer to business reality than pricing per token. Within the same score tier, the cost per task across options can differ by ten to twenty percent, and the gap can approach nearly double when compared with a higher-priced option. This is the most decision-relevant column during model selection.

    2.4 Output Inflation Rate

    If the new version needs about twenty percent more output tokens to complete the same task, actual spending may still rise even with unchanged unit prices. This item is the easiest to overlook, yet it directly determines the real ROI after an upgrade.

    3. Calculating Costs Clearly: A Reusable Estimation Script

    Before integration, run offline estimation with real business samples rather than relying on marketing claims:

    1. # Illustration: cost per task estimation; prices and coefficients must follow the service provider's public information
    2. def task_cost(in_tok, out_tok, cached_in_tok, price):
    3. p_in, p_out, p_cache = price["in"], price["out"], price["cache"]
    4. uncached = max(in_tok - cached_in_tok, 0)
    5. return uncached * p_in + cached_in_tok * p_cache + out_tok * p_out
    6. # Run the previous and new generations on the same task set, and compare total cost rather than unit price
    7. samples = load_real_tasks() # real business request set
    8. old_total = sum(task_cost(s.i, s.o, s.c, PRICE_OLD) for s in samples)
    9. new_total = sum(task_cost(s.i, s.o, s.c, PRICE_NEW) for s in samples)
    10. print(old_total, new_total, new_total / old_total)

    The key point is that the numerator and denominator must use the same task set, the same prompts, and the same evaluation criteria, so that “capability improvement” can be separated from “token inflation.”

    4. Six Engineering Techniques for Cost Optimization

    • Prefix-cache-friendly design: Put stable system instructions, tool descriptions, and few-shot examples at the very front of the prompt, and place variable parts at the end to maximize cache hits. Illustrative structure:
    1. [fixed prefix: role setup + tool schema + long-term rules] ← cacheable
    2. [session/task context] ← variable
    3. [current-turn instruction] ← variable
    • Output constraints: Use explicit format and length constraints (field lists, maximum item counts, structured output modes) to compress redundant expression and directly suppress output inflation.
    • Tiered routing: Send simple requests to smaller or lighter models, and escalate only complex reasoning and long-horizon tasks to higher-capability models.
    • Batching and asynchronization: Merge requests for tasks that can be delayed to improve throughput and reduce unit cost.
    • Reuse and deduplication: Apply semantic caching to repeated questions, so a cache hit incurs zero model cost.
    • Observability: Instrument input, output, cache hits, and cost per task by business dimension, and set budget thresholds with monitoring and alerts to avoid unnoticed abnormal inflation.

    5. Selection Guidance Based on Capability Focus

    When a new version focuses on strengthening coding, defensive security analysis, and long-horizon AI agent tasks, these three scenarios share common traits: long context, many interaction turns, and highly structured output. They benefit most from cache discounts and are also the most prone to output inflation. The engineering response is to break tasks into verifiable small steps, cap the output size of each step, and close the loop with automated tests or rule-based validation, instead of asking the model to produce an extremely long result in one shot.

    6. Conclusion

    “Unchanged unit prices and cross-generation scores” are only the entry ticket. What truly determines cost is the cost-per-task column: at the same intelligence level, whoever drives down the cost per task is better suited to carry scaled business workloads. Incorporate cache hit rate, output length, and task success rate into the evaluation, and continuously run regression estimation with real samples, so that cost benefits arrive alongside capability upgrades. If you use model services on Baidu AI Cloud, it is likewise recommended to build this estimation and observability loop with general-purpose capabilities (log service, monitoring and alerting, object storage, and message queue).