LLM API Cost Engineering: Why Unit Price Doesn't Equal Cost per Task

    As LLM API list prices stay flat, real bills can still rise. This article explains why unit price is not the same as cost per task, how to read composite intelligence scores correctly, and which cost levers matter most: cache hit rate, output token growth, and retries. It also covers a practical cost accounting method based on per-task metrics, optimization tips for coding and long-running agent workloads, and model selection and budget governance practices.

    1. The Phenomenon: The Unit Price Stays the Same, but the Bill Can Go Up

    When a cloud provider recently launched a new generation of general-purpose LLM APIs, it used a typical pricing approach: capability scores improved noticeably, while the per-million-token prices for input, output, and cached input stayed the same as the previous generation. Cached input is usually priced at only a small fraction of standard input, which works out to roughly an 80% discount.

    If you only look at unit price, this is a pure “more capability at the same price” release. But switch your view from “how much per million tokens” to “how much to complete one business task,” and the conclusion may flip: on some tasks, the new generation consumes about 20% more output tokens than the previous one. The unit price is unchanged, usage goes up, and the final bill can still increase.

    This is the most common and most easily overlooked trap in cost engineering: unit price is not the same as cost per task. What actually determines your budget is the product of the factors in this identity:

    1. cost per task ≈ input tokens × input price
    2. + output tokens × output price
    3. + cache-hit tokens × cache price
    4. + cache-miss tokens × input price
    5. + extra consumption from retries and failed calls

    If any single factor gets worse, it can eat up the savings from an unchanged unit price.

    2. How to Correctly Interpret the “Intelligence Score”

    The composite intelligence index common in the industry usually normalizes and weights results from multiple evaluation dimensions to enable tier-to-tier comparison. Its value is in quickly judging whether a model has moved up a tier, but it has three inherent limitations that must be clear during selection:

    1. It is a capability scale, not a cost scale. Within the same score tier, the cost per task can differ by several times across models. Treating “same score” as “same price” is where budgets start to spiral.
    2. It is an average scale, not your business scale. The task distribution in public benchmarks often differs from real business distribution, and scores carry very different weights for scenarios such as long context, tool calling, and structured output.
    3. It is a static scale and does not reflect your engineering implementation. With the same model, differences in prompt design, context trimming, and cache hit rate can make costs differ by more than a factor of two.

    So the recommended order is: use the composite score to narrow down candidate tiers, validate effectiveness with a self-built business evaluation set, and make the final decision based on cost per task. The score decides whether a model is usable; cost decides whether you can afford to use it.

    3. Three Underrated Cost Levers

    3.1 Cache Hit Rate: The Most Direct Discount

    Cached input is cheap because the prefix does not need to be recomputed. To get this discount, the prerequisite is a stable prefix. In practice, layering prompts as follows usually improves the hit rate noticeably:

    1. [stable layer] system instructions, tool definitions, output format constraints, a few fixed examples
    2. [semi-stable layer] domain knowledge, retrieved document chunks (reused per batch)
    3. [variable layer] current-turn user input, timestamps, random IDs

    There are three key engineering constraints: always put variable content last; do not concatenate timestamps, random numbers, or request IDs into the system prompt; and keep the ordering of retrieved chunks stable, so the same question does not fail the prefix because of a different recall order each time.

    3.2 Output Token Bloat: The Most Hidden Cost Amplifier

    Output price is usually significantly higher than input price, so output length is more sensitive for the bill. The new generation tends to produce more complete reasoning and explanations, which improves quality but also brings about 20% more output. Controllable measures include:

    • Explicitly constrain the output structure, using field-based formats instead of free-form prose;
    • Turn off lengthy explanations for internal calls that do not need them, keeping only conclusion fields;
    • Set reasonable output limits and handle truncation on the business side;
    • Split “think first, then answer” chains into small steps to avoid generating very long content in one shot.

    An illustrative structured constraint:

    1. {
    2. "schema": {
    3. "summary": "string, <=120 chars",
    4. "changes": ["string"],
    5. "risk": "none|low|high"
    6. },
    7. "note": "Do not output explanatory paragraphs unrelated to the schema"
    8. }

    3.3 Retries and Failed Calls: Invisible Noise in the Bill

    Retries caused by timeouts, rate limits, or format violations can multiply consumption. It is recommended to generate a trace ID for each call, record input/output/cached tokens and latency, and bring retry counts into the cost dashboard; for format-related failures, prefer validation and automatic repair over resending the whole round.

    4. A Practical Method for Accounting Cost per Task

    Do not rely on a single average price estimate; build a cost ledger by business action. A minimal usable record structure is:

    1. task_id, scene, model_tier,
    2. in_tokens, out_tokens, cache_hit_tokens,
    3. latency_ms, retry_count, status

    On top of this, compute three core metrics:

    • Cost per task: group by scenario and compute the mean and percentiles, focusing on P95 rather than the mean alone;
    • Cache hit rate: hit tokens / total input tokens; when it is below expectations, first check prefix stability;
    • Effective cost: cost per task / task success rate, to avoid the false savings of “cheap but repeatedly failing.”

    When the new generation’s output tokens rise by 20%, cost per task can still stay flat or even drop, as long as the cache hit rate improves at the same time and the retry rate falls. This is why “same score, different price” must be settled with measured data, not inferred from a price table.

    5. Optimization Tips for Coding and Long-Running Agent Tasks

    Coding tasks and long-running agent tasks are the two scenarios under the greatest cost pressure, and they share one trait: context accumulates repeatedly. Viable strategies include:

    1. Context layering and trimming: keep the task goal, constraints, and key conclusions from the most recent rounds; summarize and archive historical tool outputs; when necessary, store large artifacts in object storage and put only the reference address back into the context.
    2. Slimming down tool return values: agree that tools return only necessary fields and pagination cursors, avoiding whole logs entering the context.
    3. Phased execution: split long tasks into planning, execution, and verification, with separate output limits and budget thresholds for each phase; pause and request confirmation when a threshold is exceeded.
    4. Defensive security up front: isolate external input and apply least privilege, and put security checks before tool calls to reduce repeated consumption from rework.
    5. Observability support: use logging services and monitoring alerts to set threshold alarms on token consumption, cache hit rate, and failure rate, so cost anomalies surface within minutes.

    6. Model Selection and Budget Governance Recommendations

    • Build a three-dimensional selection table of “score—effectiveness—cost,” and retest with real business samples once per quarter;
    • Set cost budgets and fallback strategies for different scenarios, automatically switching to a more economical tier during peak periods;
    • Add cache hit rate and output length to the code review checklist, treating them as metrics on par with correctness;
    • Mix and orchestrate open-weight models and hosted APIs: route sensitive or high-frequency short tasks through a low-cost path, and complex reasoning through a high-score tier.

    7. Conclusion

    Capability upgrades and stable unit prices appearing together do not mean costs will automatically fall. What really determines the bill is cache hit rate, output length, retry rate, and context management quality. Only by making cost per task a first-class metric in the engineering system can you keep reaping the real benefit of “capability goes up, cost does not” across model iterations.