LLM Model Selection and Cost Accounting: A Practical Guide

    Choosing a large language model based on per-token price alone often leads to higher-than-expected bills and hidden quality issues. This guide explains how to turn published pricing rules into a computable layered model, measure cost per task instead of per million tokens, read capability benchmarks in separate categories, and audit the execution path rather than only the final output. It includes estimation and per-task accounting pseudocode, a list of common sources of cost drift, governance practices such as full-chain logging, sampling review, routing, budget guardrails and cache governance, and a deployment checklist. It also notes that Baidu AI Cloud users can build this accounting and governance setup on top of logging, monitoring and alerting, and container platform capabilities.

    1. The Starting Problem: Why “Half the Price” Does Not Mean “Half the Bill”

    In model selection, the most common decision basis is the sticker price: how much per million input tokens, how much per million output tokens. The comparison is intuitive but easily misleading. A real bill is not a single division; it is a mixed calculation layered on top of a series of conditional branches: whether the request length triggers a tier, whether a cache hit occurs, whether batch or accelerated channels are used, and whether failed retries consume extra tokens.

    A typical scenario: a team notices that a new model costs half as much per token as the incumbent, migrates a large volume of tasks to it, and validates only whether the final output is correct without tracking the intermediate process. After running for a while, two problems surface at once. First, the month-end bill drops far less than expected. Second, some tasks develop a stable but subtle bias, because the results “look right” and were never spot-checked.

    This is analogous to team management: a new hire’s salary is half that of an existing member, their output is basically usable, so the manager assigns more tasks and inspects only deliverables, without caring whether shortcuts were taken, processes were bypassed, or work was repeatedly redone. In the short term labor cost falls; in the long term neither the total account nor quality necessarily improves. Model selection works the same way: the sticker price must be converted into two dimensions, task cost and quality cost.

    2. Breaking Pricing Rules into a Computable Layered Structure

    To predict cost accurately, first formalize the pricing system. The billing logic of a single request can be expressed in pseudocode:

    1. def estimate_cost(input_tokens, cached_tokens, output_tokens,
    2. long_context=False, mode="standard"):
    3. in_rate, cache_rate, out_rate = BASE_IN, BASE_CACHE, BASE_OUT
    4. if long_context:
    5. in_rate *= 2
    6. cache_rate *= 2
    7. out_rate *= 1.5
    8. if mode == "batch":
    9. factor = 0.5
    10. elif mode == "flex":
    11. factor = 0.5
    12. elif mode == "fast":
    13. factor = 2.0
    14. else:
    15. factor = 1.0
    16. return (input_tokens * in_rate
    17. + cached_tokens * cache_rate
    18. + output_tokens * out_rate) * factor

    Four categories of variables deserve particular attention:

    1. Long-context tiers: when a single request’s input exceeds a threshold, the input and cache rates for the whole request double and the output rate rises, applying to the entire request rather than only the excess portion. This makes the bill extremely sensitive to a small number of very long requests.
    2. Separate cache read and write pricing: a cache hit read is usually significantly cheaper, but cache writes and retention duration are billed separately, and the longer the retention, the higher the unit price. Caching only pays off in high-reuse scenarios.
    3. Channel differences: batch and flex channels are usually discounted from standard pricing, but the cost is queueing latency or limited throughput; the accelerated channel carries the highest price multiple and suits interactive scenarios rather than batch jobs.
    4. Output share: output unit prices are generally higher than input, and the impact of output length on total cost is often underestimated.

    3. Task-Level Cost Accounting: Replacing Division with a Mixed Calculation

    The correct approach uses cost per task as the unified measure rather than per-million-token unit price. Different models need different token counts to complete the same task: longer reasoning chains, more retries, and more verbose structured output all raise actual consumption.

    An illustrative accounting script:

    1. def cost_per_task(model, tasks):
    2. total = 0.0
    3. for t in tasks:
    4. r = model.run(t)
    5. total += estimate_cost(r.input_tokens, r.cached_tokens,
    6. r.output_tokens, r.long_context, r.mode)
    7. if r.retry:
    8. total += estimate_cost(r.retry_input, 0, r.retry_output, False, "standard")
    9. return total / len(tasks)

    Common sources of deviation in practice include: very long requests triggering a whole-request doubling, enabling the accelerated channel to meet deadlines, insufficient cache reuse so write costs cannot be amortized, and silent retries after validation failures. Once these factors are included in the model, a sticker-price “half” often converges to an actual saving of “a bit over forty percent.” The conclusion: any selection decision should come with its accounting basis and assumptions, otherwise it is not reproducible.

    4. Reading the Scorecard in Columns: Capability Boundaries and Evaluation Methods

    Capability scores in published materials need to be broken apart, at minimum into three columns: general knowledge and language understanding, code and structured output, and long context and multi-step reasoning. Also check whether evaluation conditions are comparable: sampling parameters, prompt templates, whether tool calls are allowed, and whether results are averaged over multiple runs all change the conclusion.

    A more reliable approach is to build your own evaluation set covering the real business distribution, and to measure the following metrics separately:

    • Task success rate (the proportion of results directly consumable by downstream systems)
    • Structured output compliance rate (missing fields, wrong types, extra explanation)
    • Long-context recall and resistance to distraction
    • Latency distribution (P50/P95), not the average
    • Cost per task and failure retry rate

    5. Process Auditing: Do Not Only Check Whether the Result Is Correct

    The most important warning in the original scenario is “looking only at results, not the path.” In a real system, a model may arrive at the correct answer through external retrieval, tool calls, or even prompt injection. Such paths are not reproducible or controllable in production. Recommended governance measures:

    1. Full-chain tracing: log request parameters, cache hit status, the tool call sequence, token consumption and billing tier, all written into a unified logging service.
    2. Sampling review: keep a manual spot-check ratio for high-value tasks, and use rule-based validators to automatically compare low-value tasks.
    3. Routing strategy: tier by task complexity, sending simple tasks to low-cost channels and escalating complex tasks to higher-capability models, avoiding a one-size-fits-all migration.
    4. Budget guardrails: set quotas and alerts by task type and by caller, and configure cost thresholds in the monitoring and alerting system.
    5. Cache governance: track cache hit rate and write amortization period, and disable caching when the hit rate falls below a threshold to avoid wasted writes.

    6. Deployment Checklist

    • Are decisions made on task-level cost rather than unit price?
    • Have you measured the share of very long requests and their effect on whole-request rates?
    • Does the usage ratio of batch and accelerated channels meet the business latency requirements?
    • Have you established structured output validation and failure retry metering?
    • Have you audited samples where “the result is correct but the path is abnormal”?
    • Does the evaluation set come from the real business distribution with fixed evaluation parameters?

    7. Conclusion

    The essence of model selection is not finding the cheapest unit price, but finding an explainable balance point among cost, latency and quality. Formalizing the pricing rules, unifying the cost measure at the task level, and making quality validation and process auditing routine are what prevent the triple gap of “sticker price halved, bill not reduced, bias quietly stored.” If an organization already uses relevant Baidu AI Cloud capabilities, it can build the accounting and governance system described above on top of logging, monitoring and alerting, and container platform capabilities, making selection conclusions reproducible and open to continuous optimization.