LLM Model Selection and Cost Governance: A Practical Guide for AI Inference Chains

    Choosing the right large language model is rarely about finding a single "best" model. This guide explains how to align usage metrics, tier models by task difficulty, implement routing and fallback in code, and apply four cost-control levers—caching, batching, context reduction, and quotas. It also covers building an observability and evaluation loop so model selection becomes a measurable engineering process rather than a matter of preference. The content is based on the original Chinese article and preserves its structure, code examples, and conclusions.

    1. The Starting Point: Why “Which Model Feels Most Convenient” Is the Wrong Question

    In real projects, the question “which LLM is the most convenient to use” is almost impossible to answer in one sentence. The model that feels best during local testing is often not the one with the highest production call volume or the largest share of the bill. Meanwhile, the model with the highest cost is usually not the best-performing one—it has simply been placed on a high-frequency path by mistake.

    Abstracting a typical set of call statistics reveals three recurring structural facts:

    • Call volume is highly concentrated. A few models handle the vast majority of requests, with the top models often accounting for more than 80% of total volume.
    • Cost distribution is not proportional to call volume. A high-priced model may account for only a single-digit percentage of calls yet consume more than one-third of the total budget.
    • Quality and cost are not monotonically related. Within the same tier, models differ significantly in cost-effectiveness. Blindly choosing “higher is better” or “lower is better” both lead to waste.

    Therefore, selection should not start from “which model I like” but from “what this path requires.”

    2. Aligning Metrics First: Three Indicators Are Indispensable

    Many cost debates actually stem from inconsistent metrics. It is recommended to fix three basic indicators in your monitoring and billing systems:

    1. Call volume (request count / normalized token volume). Request count reflects path pressure, while token volume reflects actual resource consumption. Both must be tracked.
    2. Cost and its share. Look at both the absolute amount per model and its share of total cost—the share is the basis for prioritizing governance.
    3. Cost per unit of effective output. This means “cost per thousand successful business operations,” amortizing failed retries, overly long contexts, and invalid outputs to avoid being misled by surface-level unit prices.

    A schematic aggregation logic can be written as:

    1. # Pseudocode: aggregate model-level metrics by day
    2. daily = defaultdict(lambda: {"req": 0, "tokens": 0, "cost": 0.0, "fail": 0})
    3. for rec in usage_log:
    4. d = daily[(rec.date, rec.model_alias)]
    5. d["req"] += 1
    6. d["tokens"] += rec.prompt_tokens + rec.completion_tokens
    7. d["cost"] += rec.estimated_cost
    8. d["fail"] += int(rec.status != "ok")
    9. # Key derived metrics
    10. for (date, alias), d in daily.items():
    11. d["cost_share"] = d["cost"] / total_cost_of(date)
    12. d["cost_per_1k_req"] = d["cost"] / max(d["req"], 1) * 1000
    13. d["retry_amplified_cost"] = d["cost"] * (1 + d["fail"] / max(d["req"], 1))

    With these three indicators, “convenience” is translated into comparable engineering language.

    3. Tiered Selection: Allocate by Task Difficulty, Not Brand Preference

    A mature approach abstracts models into capability tiers rather than memorizing specific model names. The industry typically divides them into three tiers:

    • Flagship tier: tasks with low error tolerance, such as complex reasoning, long-document understanding, multi-step tool calling, and code refactoring.
    • Balanced tier: daily Q&A, structured extraction, and routine code completion—this tier handles the bulk of requests.
    • Light tier: short-output tasks such as intent recognition, tag classification, format conversion, and fallback on cache misses.

    The core principle of tiering is to let the flagship tier handle only requests that truly need it. A counterintuitive but effective lesson from practice is that misrouting a large number of “seemingly simple” requests to the flagship tier is the single most common cause of cost overruns.

    4. Routing and Fallback: Encoding Selection into Code

    The routing layer should be implemented as an independent component that takes request features as input, outputs a target tier, and supports automatic fallback on failure.

    1. def pick_tier(req):
    2. # 1) Rules first: explicitly simple tasks go to the lower tier
    3. if req.task_type in {"classify", "normalize", "tag"}:
    4. return "light"
    5. # 2) Complexity estimation: length, tool usage, retry history
    6. if req.est_tokens > 24000 or req.needs_tools or req.retry_count > 0:
    7. return "flagship"
    8. return "balanced"
    9. async def call_with_fallback(req, registry):
    10. order = {"light": ["light", "balanced"],
    11. "balanced": ["balanced", "flagship"],
    12. "flagship": ["flagship"]}[pick_tier(req)]
    13. last_err = None
    14. for tier in order:
    15. try:
    16. return await registry[tier].invoke(req)
    17. except (TimeoutError, RateLimitError) as e:
    18. last_err = e
    19. await sleep(backoff(tier))
    20. raise last_err

    Fallback should only go “upward as a safety net,” never “downward to save money,” otherwise recoverable errors would turn into business errors.

    5. Four Levers for Cost Governance

    1. Tiered caching. Use exact caching for highly deterministic requests and similarity caching for semantically similar requests, with clear expiration policies. A ten-percentage-point increase in cache hit rate often saves more than switching models.
    2. Batching and asynchronization. Convert offline extraction and batch summarization tasks to queue-driven batch processing, use message queues to smooth peaks, and store intermediate results in object storage to avoid premium tiers being crowded out during peak hours.
    3. Context slimming. In retrieval-augmented scenarios, perform reranking and redundancy removal first, and control the number of injected snippets. Halving the context usually reduces cost and latency simultaneously.
    4. Quotas and isolation. Set token quotas and concurrency limits per business line, combined with monitoring and alerting, to prevent a single abnormal caller from draining the overall budget.

    6. Observability and the Evaluation Loop

    Selection without evaluation is just opinion. It is recommended to build a small, repeatable offline evaluation set covering typical intents and boundary samples, recording quality, P95 latency, and unit cost to form a loop of “evaluation—canary—full rollout—retrospective.” On the production side, uniformly collect request logs, token metering, and status codes into logging and monitoring/alerting systems so that cost anomalies at any model dimension can be located within minutes.

    In related practices at Baidu AI Cloud, such capabilities are typically carried by combinations of general cloud product categories such as model services, container platforms, message queues, object storage, and monitoring/alerting. Teams only need to focus on routing strategies and evaluation standards themselves.

    7. Deployment Checklist

    • Have you established a model inventory by tier rather than by model name, with clear entry and exit criteria for each tier?
    • Are there paths where “simple requests go to the expensive tier,” and what percentage do they represent?
    • Are cache hit rate, retry rate, and average context length included in daily dashboards?
    • Do you have upward fallback and quota isolation to prevent a single point of failure from escalating into a budget incident?
    • Is the evaluation set updated alongside business iterations, and are selection conclusions backed by data?

    The conclusion is straightforward: the most convenient model is not any single one, but a mechanism that accurately assigns requests to the appropriate tier and provides a safe fallback during anomalies. Unify the metrics, encode routing into code, and break cost down into observable indicators—then model selection shifts from subjective preference to a continuously optimizable engineering metric.