Large Language Model Selection: Balancing Cost, Quality, and Latency in Practice

    This article explains why asking which LLM is "the best" is the wrong starting point, and instead frames model selection as a trade-off among cost, quality, and latency. It covers three common trade-off profiles, scenario-based decision paths, layered routing that splits traffic into real-time, quality, and offline pipelines, a quantifiable evaluation method with concrete metrics, and practical techniques for controlling cost and ensuring stability. Readers will learn how to turn model selection into a weight-allocation problem and implement it with routing and repeatable evaluation.

    1. Background: Why “Which Model Is the Best?” Is the Wrong Question

    In real engineering projects, teams often face several lightweight large language models with similar positioning and struggle to reach a single answer. The reason is not that the models differ dramatically in capability, but that application scenarios are sensitive to three different things: answer quality, invocation cost, and response latency. One valuable observation from the original discussion is that when prompts and skill orchestration are well designed, the quality gap among a few models on “rough work” tasks is not significant; what really separates the user experience is speed and stability.

    Therefore, selection should not start from a “leaderboard” but from “constraints”: first define the business’s upper limit for latency tolerance, its acceptance criteria for quality, and its budget boundary for cost per invocation, then filter candidate models in reverse.

    2. Core Framework: The Impossible Triangle of Cost, Quality, and Latency

    A widely accepted engineering rule of thumb is that all three are hard to optimize at the same time. It can be illustrated as follows:

    1. # Pseudocode: selection scoring, with weights determined by the business scenario
    2. candidates = [
    3. {"name": "Candidate A", "quality": 0.7, "cost": 0.9, "latency": 0.2},
    4. {"name": "Candidate B", "quality": 0.9, "cost": 0.5, "latency": 0.8},
    5. {"name": "Candidate C", "quality": 0.7, "cost": 0.2, "latency": 0.8},
    6. ]
    7. weights = {"quality": 0.5, "cost": 0.2, "latency": 0.3} # interactive scenario
    8. best = max(candidates,
    9. key=lambda m: sum(m[k] * weights[k] for k in weights))

    Three typical trade-off profiles:

    • Quality-first: high quality, medium cost, higher latency. Suitable for offline batch processing, complex reasoning, and long-document understanding.
    • Cost-first: low cost, medium quality, higher latency. Suitable for scheduled jobs, log cleaning, and processing massive volumes of low-value text.
    • Latency-first: low latency, medium quality, higher cost. Suitable for real-time interaction, intelligent code completion, and instant voice and multimodal responses.

    It is worth stressing that latency itself should be split into two metrics: time to first token (TTFT) and output throughput (TPS). Some models return the first token quickly but stream slowly; others take longer to start but deliver stable throughput. The two have very different effects on the feel of high-frequency, small-step interactions.

    3. Scenario-Based Decision Paths

    1. Real-time interaction and intelligent coding tools: latency carries the highest weight. TTFT directly determines whether users keep using the tool. Set a clear threshold (for example, keep first-token response in the sub-second range) and load-test output throughput.
    2. Batch and scheduled jobs: latency-insensitive; cost and stability come first. Such tasks can tolerate completion times on the order of minutes, so budget constraints should be the top priority, along with stable output formats and retryability.
    3. Near-flagship substitution and complex tasks: quality first, with higher cost and higher latency allowed, but timeouts and fallback strategies must be in place.
    4. Hybrid orchestration: use the “high-quality, high-cost” model for planning and key decisions, and the “low-cost” model for execution and filling, forming layered invocation.

    4. Layered Routing: Splitting the Triangle into Two Pipelines

    A more mature engineering approach is not an either-or choice but building a routing layer:

    1. User request
    2. ├─ Intent classification (rules / small model)
    3. ├─ Real-time pipeline -> low-latency model (interaction, completion)
    4. ├─ Quality pipeline -> high-quality model (planning, review)
    5. └─ Offline pipeline -> low-cost model (batch processing, scheduled jobs)

    The routing layer needs supporting mechanisms: timeouts and retries, fallback to a backup model on failure, quotas set per tenant or scenario, and quality spot-check samples recorded for every invocation. This avoids the rigidity of “one model for everything” and makes cost predictable.

    5. A Quantifiable Evaluation Method

    Do not rely on subjective impressions; build a small but fixed evaluation set:

    • Metrics: task success rate, format compliance rate, TTFT P50/P95, output tokens per second, and cost per task.
    • Method: compare candidates horizontally under the same prompt, the same temperature setting, and the same concurrency; run each candidate model at least three rounds and take the median.
    • Regression: rerun the evaluation set after any prompt or model version change to prevent quality regression.

    6. Cost and Stability Safeguards

    • Caching and deduplication: cache results for high-frequency repeated requests to significantly cut invocation volume.
    • Context trimming: control input length; for long documents, summarize in segments first and then run inference.
    • Concurrency and rate limiting: reserve a separate quota for latency-sensitive pipelines so they are not squeezed out by offline tasks.
    • Observability: combine logging services with monitoring and alerting, and track latency, error rate, and cost on dashboards.

    7. Conclusion

    The quality gap among lightweight models is often smaller than the experience gap created by scenario constraints. Turning the selection problem into a question of how to allocate weights within the cost-quality-latency triangle, then landing it with layered routing and quantifiable evaluation, is the sustainable engineering answer. If an enterprise wants to implement the architecture described above on Baidu AI Cloud, it can directly use general-purpose capabilities (for example, a container platform to host the routing layer, logging services with monitoring and alerting for observability, and object storage to keep evaluation samples), without being locked into any single model.