LLM API Cost Benchmarking and Model Selection: A Practical Optimization Guide

    This article explains why the cheapest per-token price does not always produce the cheapest bill, and how to build a reproducible cost model for LLM APIs. It covers fitting input, output, and cache prices from real usage, estimating real capacity under credit or quota limits, routing tasks across model tiers by cognitive difficulty, and using prompt-prefix stability and caching to reduce input costs. It also outlines validation and governance practices for production deployments.

    1. Why a Low Unit Price Does Not Mean a Low Bill

    When building an intelligent coding assistant, a document review pipeline, or a multi-agent system, teams often start by comparing the per-million-token prices of available models and make their selection on that basis. Once the real bill arrives, however, the result frequently diverges from expectations: the model with the lowest unit price ends up costing more per month, or an expensive model produces a surprisingly small bill.

    There are three reasons for this. First, pricing usually has separate tiers for input, output, and cache hits, while most people only remember the input price. Second, the input-to-output ratio varies enormously across tasks: code generation is output-heavy, while retrieval-augmented tasks are input-heavy. Third, the cache-hit price can be only a few percent of the normal input price, so once a system has stable prefix reuse, the structure of the bill is rewritten entirely.

    The right approach, therefore, is not to compare unit prices but to build a verifiable cost model and then calibrate it with real usage.

    2. Reverse-Engineering Unit Prices from the Bill

    Consider a credit-based calling platform that offers several tiers of LLM capability, with a price spread spanning up to two orders of magnitude. Least-squares fitting can decompose credit consumption into per-tier unit prices.

    Let the credits consumed by the i-th call be:

    1. cost_i = a * input_i + b * output_i + c * cache_i

    where a, b, and c are the unit credits for input, output, and cache hits respectively. Organize all call records over a period into a matrix and solve the linear system.

    A typical fit produces the following results: the top-tier model’s output price is roughly two hundred times that of the lowest tier; the mid-tier reasoning model is about 3,200 credits per million input tokens and about 112,000 credits per million output tokens; the main execution tier is about 4,000 for input and 8,000 for output; the lightweight tier is 2,000 for both. The cache-hit tier is as low as 80 credits per million tokens, just 2% of the normal input cost.

    Fit quality matters just as much. If the coefficient of determination reaches 1.0 and the residuals approach zero, the model form matches the actual billing rules and can be used confidently for budget projections. If the residuals are significant, it usually means something is missing, such as tiered pricing, a minimum billing unit, or failed-call retries.

    Note that the figures above come from personal benchmarking and reverse-engineering, not from an official price list. The rules can change at any time, so always defer to what the service provider publishes.

    3. Measuring Real Capacity Under Quota Limits

    Credit-based platforms commonly express quotas as “60,000 credits per five hours and 600,000 credits per week.” Assuming input accounts for 80% and output for 20%, with caching excluded for now, the sustainable token volume per tier works out to:

    • Top tier: about 417,000 tokens / 5 hours
    • Mid-tier reasoning: about 1,250,000
    • Main execution: about 12,500,000
    • Lightweight tier: about 30,000,000

    The gap is on the order of thirty to seventy times. This number is more useful for decision-making than any price table, because it directly answers “how much work can my quota actually run.”

    The estimation script can be minimal:

    1. def capacity(budget, in_price, out_price, in_ratio=0.8):
    2. blended = in_ratio * in_price + (1 - in_ratio) * out_price
    3. return budget / blended * 1_000_000

    4. Tiered Scheduling: Expensive Models Think, Cheap Models Execute

    Given the capacity differences above, a sound architecture allocates work by cognitive difficulty rather than by team preference:

    1. Planning and final review: task decomposition, approach selection, code review, risk identification. Low call volume but high cost of error, so use the top-tier model.
    2. Complex reasoning: cross-file refactoring, difficult defect localization, algorithm design. Moderate call volume, so use the mid-tier reasoning model.
    3. Main execution: routine code completion, unit test generation, script writing. Highest call volume, so use the main execution tier.
    4. Batch processing: log categorization, comment generation, format conversion, simple Q&A. Use the lightweight tier, where cost is negligible.

    The routing logic can be implemented with rules plus confidence:

    1. def route(task):
    2. if task.risk == "high" or task.step == "review":
    3. return "tier_reasoning_max"
    4. if task.needs_cross_file_reasoning:
    5. return "tier_reasoning_mid"
    6. if task.batch and task.complexity <= 1:
    7. return "tier_light"
    8. return "tier_main"

    In practice, log the tier, token composition, and credit consumption of every call to build a traceable cost dashboard, and wire it into monitoring and alerting so that a tier can be throttled or downgraded promptly when its consumption rate spikes.

    5. Caching: The Underrated Cost Lever

    When the cache-hit price is 2% of the normal input price, the dominant variable in the bill is not model choice but prefix stability. Practical measures include: keeping the system prompt, tool definitions, and codebase index summary fixed at the very front of the request with no dynamic concatenation; chunking long documents in a stable order; avoiding volatile content such as timestamps or random identifiers inserted mid-session; and building a semantic cache for high-frequency repeated questions.

    A counterintuitive conclusion follows: making prompts longer and more structured can lower total cost, as long as the prefix stays stable. Conversely, rewriting the prefix dynamically to “save words” keeps breaking the cache.

    6. Validation and Governance

    Before a model goes live, do three things: validate the fitted unit prices with a small-sample regression; run shadow traffic to compare predicted credits against actual credits; and establish cost attribution by project and by person. Also keep a fallback path in place so that calls switch automatically when a higher tier’s quota is exhausted, preventing tasks from stalling.

    7. Conclusion

    The essence of cost optimization is turning “which model should I pick” into “which tier should bear each token.” Quantify capacity first, then apply tiered routing, and finally use caching and prefix governance to push input costs down. This method applies to any platform billed by credits or tokens, and can be implemented alongside the general-purpose model services, logging, and monitoring and alerting capabilities offered by Baidu AI Cloud.