Cost Evaluation and Model Selection for Large-Scale Model APIs

    This article explains why falling API unit prices can still lead to higher bills, and how to evaluate large-scale model APIs by cost per business task instead of price per million tokens. It covers building a unit-task cost metric, four practical optimization levers—context trimming, prefix reuse, tiered routing, and output constraints—plus cost observability, alerting rules, and a validation workflow to run before upgrading models. The approach is vendor-neutral and can be applied to mainstream large model services and general capabilities on Baidu AI Cloud.

    1. The Real Issue: Lower Unit Prices and Higher Bills Are Not Contradictory

    A recent iteration of a trillion-parameter-class model sparked debate, with much of the criticism focused on it being “expensive.” But if you break the bill down, a common misconception appears: treating “unit price” and “total spend” as the same thing.

    Unit prices are indeed falling. The previous generation’s input price was about 20 RMB per million tokens, and the new generation’s input unit price is below that level. Total spend, however, is determined by four variables:

    1. Total cost ≈ (input tokens × input unit price) + (output tokens × output unit price) + retry and failure overhead + add-on capability overhead

    As model capabilities improve, a single request tends to carry longer context, more complete tool definitions, and more turns of history, and the output gets longer too. If input volume triples, the bill still goes up even with a 30% discount on unit price. This is not a pricing problem but a usage problem.

    So the right question when judging whether a model is “expensive” is: what is the unit cost of completing the same business task—not how much it costs per million tokens.

    2. Define a Unit-Task Cost Metric

    Push the cost metric down to business granularity rather than leaving it at billing granularity.

    1. # Example: unit-task cost accounting
    2. def cost_per_task(records):
    3. total_in = sum(r["in_tokens"] for r in records)
    4. total_out = sum(r["out_tokens"] for r in records)
    5. cost = total_in / 1e6 * PRICE_IN + total_out / 1e6 * PRICE_OUT
    6. return cost / len(records) # average cost per task

    With this metric in place, you can answer three key questions: which request types consume most of the budget; whether per-task cost rises or falls after a model upgrade; and how much a given optimization actually saves. In practice, long-context applications usually have input tokens making up the overwhelming majority, so optimization should focus on the input side.

    3. Four Levers for Cost Optimization

    3.1 Context Trimming

    Replace “stuff all the material into the prompt” with “include only the fragments relevant to the current request.” In retrieval-augmented scenarios, controlling the number of recalled items and fragment length, and removing duplicate and low-information content, usually yields a substantial input reduction without hurting quality.

    3.2 Prefix Reuse

    Many requests share the same system instructions, tool descriptions, or knowledge prefix. Placing the stable part at the front and keeping it unchanged lets the inference side reuse the already-computed prefix and avoid repeated computation. One engineering caveat: once the prefix content changes, reuse is invalidated, so put volatile information at the end of the prompt.

    1. [Stable prefix: role setup + tool definitions + guidelines] ← kept unchanged, enables reuse
    2. [Variable part: retrieved fragments + user question + timestamp] ← changes every time

    3.3 Tiered Routing

    Not every request needs the strongest model. Small models or rules can handle intent classification, format conversion, extraction, and similar tasks, leaving only complex reasoning to the large model. The routing layer should log each decision and its result, with continuous regression calibration, so that quality on critical paths is not sacrificed to save money.

    3.4 Output Constraints

    Output length directly determines output-side cost. Constraining generation length through explicit structured formats, field limits, and conciseness requirements also reduces retry overhead from downstream parsing failures—retries are the most easily overlooked hidden cost on the bill.

    4. Make Cost an Engineering Concern

    Cost must go into the observability system instead of being reviewed only when the monthly bill arrives. Collect per-call token usage, latency, retry counts, and business identifiers; connect them to logging and monitoring with alerting; and set budget thresholds and anomaly alerts per business line. For capacity, use an elastic container platform to host the routing and caching layers, use a message queue to smooth out peaks, and put large contexts and intermediate results in object storage for on-demand reference to avoid repeated transfers.

    An example alerting rule set that can be put into practice:

    1. if avg cost per task (last 1 hour) > baseline × 1.3: alert
    2. if input token share (last 1 day) > 80%: trigger context-trimming initiative
    3. if retry rate > 5%: investigate output format constraints

    5. Validation Before Upgrading

    Model iterations should not be switched on a hunch. Four steps are recommended: first, build an evaluation set reflecting the real distribution, covering long-tail and edge cases; second, record both quality and cost metrics to form a quality–cost curve; third, run a small-traffic canary comparing per-task cost and human feedback between old and new versions; fourth, before full rollout, set a rollback switch and a budget cap.

    6. Conclusion

    “Expensive” is often a signal about how the model is being used, not a pure pricing conclusion. Switching the evaluation basis from unit price to unit-task cost, combined with context trimming, prefix reuse, tiered routing, and output constraints, and then keeping cost under control with quantification and alerting, is what keeps bills manageable as model capabilities keep improving. This approach does not depend on any specific vendor and can be carried over to mainstream large model services and the relevant general capabilities on Baidu AI Cloud.