LLM API Cost Engineering: Why Per-Token Price Is Not Your Real Bill

    As LLM API prices shift, a flat per-token rate does not guarantee a flat bill. This article breaks down why newer models can cost more per task even at unchanged pricing, how output token inflation happens, and how to measure true cost using cost per task, pass rate, and cost per successful task. It also covers four practical cost-control techniques—cache-friendly prompt design, output budgets, tiered routing, and observability—plus a model selection checklist for engineering teams.

    1. The Catch: Unchanged Unit Price Does Not Mean an Unchanged Bill

    A cloud provider recently released a new-generation general-purpose LLM API. The official pricing is unchanged from the previous generation, and a third-party evaluation benchmark raised its composite intelligence score from 53 to 60, putting it on par with another model in the same tier. On the surface, this looks like “more capability at the same price.” From an engineering billing perspective, though, only half of that statement is true.

    To judge the real cost, you need to look at four variables at the same time:

    1. The input and output price structure (output is usually priced significantly higher than input);
    2. Whether cached input is available and how large the discount is;
    3. The total number of tokens consumed to complete the same task;
    4. Cost per task (which rolls the first three factors into a single business-level unit).

    The magnitudes in the original example are representative: input is about $1.40 per million tokens, output about $4.40, and cached input about $0.26, meaning a cache hit is roughly an 81% discount. On a per-task basis, the 60-point model costs about $0.68 per task, a same-tier competitor about $0.84, and a higher-priced model about $1.23. However, compared with the previous generation, the same model generation consumes about 20% more output tokens per task—which means the unit price stays flat while actual spending can go up.

    The conclusion is clear: cost evaluation for model selection must move from comparing unit prices to comparing cost per task.

    2. Why Output Tokens Expand

    Output expansion is not a vendor “secretly raising prices.” It is a natural side effect of stronger capabilities, and it usually comes from four sources:

    • Longer reasoning chains: Stronger models tend to lay out a more complete thought process. If that thinking content is billed as output, costs scale up accordingly.
    • Long-running agent tasks: Multiple tool calls, state self-checks, and retries on failure all generate extra output.
    • Longer code and structured output: More rigorous implementations often include more comments, edge-case handling, and test snippets.
    • More defensive phrasing: Models with stronger safety alignment are more cautious and tend to produce more verbose output.

    So when evaluating a new model, you cannot rely on leaderboard scores alone. You need to run a “regression test plus bill regression” against a real task set from your own business.

    3. A Practical Cost Measurement Method

    Build a minimal measurement script that puts task success rate and cost per task in the same table:

    1. # Example: cost-per-task measurement framework (pseudo interfaces, logic only)
    2. def evaluate(cases, client):
    3. total_cost, passed = 0.0, 0
    4. for c in cases:
    5. r = client.chat(model=c.model, messages=c.prompt)
    6. usage = r.usage # prompt_tokens / completion_tokens / cached_tokens
    7. cost = (
    8. usage.prompt_tokens * PRICE_IN
    9. + usage.completion_tokens * PRICE_OUT
    10. + usage.cached_tokens * PRICE_CACHE
    11. ) / 1_000_000
    12. total_cost += cost
    13. passed += int(c.checker(r.text))
    14. return {"cost_per_task": total_cost / len(cases),
    15. "pass_rate": passed / len(cases)}

    Three metrics matter: cost per task, task pass rate, and cost per successful task (total cost ÷ number of successful tasks). Looking at only the first two leads to misjudgment; the third is the number the business actually cares about.

    4. Four Engineering Techniques to Cut Costs

    1. Cache-friendly design: Put long, stable system prompts, knowledge base snippets, and tool definitions at the front of the request, and keep the prefix byte-for-byte identical so cached input discounts can be hit. Move volatile content such as timestamps and random IDs to the end.
    2. Output budget constraints: Explicitly cap maximum output length, require “conclusion first, details after,” and use a fixed schema for structured results to leave less room for free-form generation.
    3. Tiered routing: Send simple requests to small models or a rules engine, and escalate only complex requests to large models. Use confidence scores or rule matches as the routing conditions.
    4. Observability first: Feed token usage, cache hit rate, and cost per task into logging services and monitoring alerts. Set budget thresholds and alerts per business line so you do not discover an abnormal bill only at month end.

    5. Selection Checklist

    • Are all three price tiers published—input, output, and cache—and can the cache discount be hit reliably?
    • Are a public intelligence score and cost-per-task data available, with a test set close to your scenario?
    • Is output controllable (maximum output, structured output, thinking budget)?
    • Are open weights or private deployment supported, making long-term cost easier to control?
    • Are usage monitoring and quota management capabilities complete?

    6. Closing Thoughts

    Once first-tier models crowd into the same score band on intelligence benchmarks, the competition shifts from “who is smarter” to “who is cheaper at the same level of intelligence.” For developers, the real moat is not chasing the newest model but building a sustainable cost engineering capability: use cost per task as the unified measure, cache and output budgets as the two levers, and monitoring alerts as the safety net. If your organization already uses Baidu AI Cloud products, you can combine the measurement logic above with logging, monitoring, and containerized deployment to close the loop from evaluation to launch to cost review.