LLM Model Selection and Cost Evaluation: A Practical Guide
This guide reframes large language model selection as a constrained optimization problem rather than a leaderboard ranking. It covers four evaluation dimensions—quality, latency, throughput and rate limits, and cost—with practical quantification methods, a reproducible selection workflow, common pitfalls, and engineering recommendations for building a configurable model gateway with observability.
1. The Core Problem: Selection Is Constrained Optimization, Not a Leaderboard
Many teams start model selection by looking at an overall leaderboard rank. In engineering practice, however, success is usually determined by constraints: the minimum acceptable answer quality for the business, the end-to-end latency budget, peak concurrency, context length, and the acceptable cost per request. Comparing models side by side in a single table—latency, input and output tokens, total consumption, credits—is a reasonable starting point, but it misses two key prerequisites: whether the task distribution matches your real traffic, and whether the cost accounting uses a consistent basis.
A more rigorous approach is to formalize the problem first: minimize the cost per valid request C, subject to a quality threshold Q_min and a latency threshold L_max. This is a constrained optimization problem, not a matter of “picking the strongest model.”
2. Four Evaluation Dimensions and How to Quantify Them
2.1 Quality: Replace Subjective Impressions with a Layered Evaluation Set
Build a three-layer evaluation set:
- Core business set: sampled from real, anonymized traffic, 200–500 items.
- Edge-case set: long documents, multi-turn references, strict format constraints.
- Regression set: historical production bad cases.
For each sample, use a three-way judgment of “rule-based validation + model review + human spot checks,” and report a pass rate rather than a single average score, because an average can hide fatal weaknesses.
2.2 Latency: Separate Time to First Token from Total Completion Time
The “model latency” and “tokens/s” figures in the source material actually correspond to two different metrics. Interactive scenarios, such as coding completion and customer support, should prioritize time to first token; batch scenarios, such as document summarization and offline labeling, should look at overall throughput. Record P50/P95/P99 instead of averages:
# Minimal approach to latency measurementimport time, statisticsdef bench(call, n=30):ttft, total = [], []for _ in range(n):t0 = time.perf_counter()first = call(stream=True).__next__() # first tokenttft.append((time.perf_counter() - t0) * 1000)for _ in call(stream=True): pass # remaining outputtotal.append((time.perf_counter() - t0) * 1000)return {"ttft_p95": sorted(ttft)[int(n*0.95)-1],"total_p95": sorted(total)[int(n*0.95)-1],"tok_per_s": statistics.mean(total and 1000/t for t in total),}
2.3 Throughput and Rate Limits: Put RPM/TPM into the Capacity Model
The source material mentions a platform rate limit of 50 RPM. Constraints like this are often overlooked in load-test reports. For capacity planning, calculate: peak QPS × average output tokens ÷ rate-limit quota = required quota multiple, and reserve headroom for bursts. If the quota is insufficient, add queuing and graceful degradation at the application layer.
2.4 Cost: Compare Only After Unifying the Accounting Basis
Billing dimensions vary widely across services. Some price input and output separately; others introduce different multipliers for cache creation and cache hits. A unified formula can be written as:
credits = input tokens × input multiplier+ cache creation tokens × cache creation multiplier+ cache hit tokens × cache read multiplier+ output tokens × output multiplier
The data in the source material illustrates a pattern: the output multiplier is usually significantly higher than the input multiplier (for some flagship models, the output multiplier can be several to tens of times the input multiplier), while lightweight models have lower multipliers overall. This means long-output tasks affect cost far more than long-input tasks. Compressing output through prompt optimization and structured short answers is often more cost-effective than switching models.
3. A Reproducible Selection Workflow
- Define scenario categories: interactive, batch, or high-security/compliance, and set
Q_minandL_maxfor each. - Sample and build the evaluation set. Start with a small sample (30 items) for coarse screening to eliminate candidates that clearly fail.
- Run a formal evaluation of 200+ items on candidates that pass coarse screening, recording quality pass rate and P95 latency.
- Apply the unified cost formula with the real token distribution (not theoretical averages) to compute
C. - Run an A/B canary: 5% of traffic for one week, monitoring failure rate, timeout rate, and credit consumption.
- Build a regression dashboard that automatically reruns the regression set when the model or prompts change.
Illustrative decision logic:
def choose(candidates, q_min, l_max):ok = [c for c in candidates if c["quality"] >= q_min and c["p95_ms"] <= l_max]return min(ok, key=lambda c: c["cost_per_valid_req"]) if ok else None
4. Common Pitfalls
- Looking at unit price instead of effective cost: retries, timeouts, and repeated calls caused by non-compliant formats can significantly raise real cost, so convert it to “cost per valid request.”
- Ignoring cache benefits: in multi-turn conversations and fixed system-prompt scenarios, the cache hit multiplier is usually far lower than the cache creation multiplier, and every 10% improvement in hit rate can change the conclusion.
- Estimating bills with average tokens: real traffic shows a clear long tail in input and output length, so use P90 length for budgeting.
- Betting everything on a single model: a safer approach is dual primary/backup paths plus task-based routing, with small models handling high-frequency simple requests and large models covering complex ones.
5. Engineering Recommendations
Abstract a unified model gateway at the application layer to hide differences in parameters and billing. Make routing policies, rate-limit queuing, caching policies, logging, and monitoring alerts configurable. Archive evaluation sets and call logs in object storage, use a message queue to smooth peaks, and run elastic inference proxies on a container platform. If you use relevant general capabilities from Baidu AI Cloud, such as log services, monitoring and alerting, and container platforms, you can connect these metrics to a unified dashboard for cost observability and quality traceability.
Summary: The right way to approach selection is to turn “which model is better” into “which combination is optimal under my quality, latency, and cost constraints,” and to keep calibrating it with a reproducible evaluation and canary process.
