LLM Inference Selection: Cost Evaluation and A/B Testing Guide
A practical guide to LLM inference selection: why token unit price is not total cost, a task-level cost model, how to run fair A/B tests, layered quality evaluation, a cost-quality frontier, and ongoing governance after launch.
1. A common mistake: low unit price is not low total cost
When evaluating general-purpose LLM inference, the most common trap is looking only at input/output price per million tokens. Unit price is just a coefficient. What actually drives the bill is how you call the model:
- Input/output mix: Long-context summarization is input-heavy; code generation is output-heavy. The two hit the bill very differently.
- Cache reuse: Stable system prompts and repeated retrieval context can cut billed input if they hit cache. Low hit rates make cache discounts irrelevant.
- Retries and multi-sample strategies: Some apps raise accuracy with extra samples or cross-checks. Going from 1 to 3 rounds raises cost almost linearly, so a slightly more expensive model that succeeds in one shot can be cheaper overall.
- Failure and timeout cost: Rate limits, timeouts, and invalid formats that force reruns are easy-to-miss line items.
Conclusion: unit price without call shape is meaningless. Convert everything to expected cost to complete one business task.
2. Write cost as a computable model
Use one accounting definition across teams:
Expected cost per task =(input tokens × input price × (1 − cache hit rate × cache discount))+ (output tokens × output price)+ expected retries × cost per attempt+ failure compensation cost
Expected retries can be estimated from historical success: if single-call success is p, expected calls are about 1/p. That explains a counterintuitive result: raising success from 0.90 to 0.97 drops expected calls from 1.11 to 1.03, often more than a unit-price gap.
3. How to design A/B tests that you can trust
Credible results need four “sames”:
- Same environment: same prompt version, retrieval content, temperature and max output length, post-processing and validation.
- Same traffic: hash on request ID so a user stays on one variant; start at 50/50 if you like.
- Same period: cover a full business cycle (weekdays and off-peak), not one day’s load.
- Same metrics: freeze quality, cost, and latency definitions before the experiment; do not change them mid-flight.
Sketch of routing and accounting:
import hashlibdef pick_variant(request_id: str, ratio: float = 0.5) -> str:h = int(hashlib.sha256(request_id.encode()).hexdigest(), 16) % 10000return "A" if h < ratio * 10000 else "B"def record(usage, variant, task_id):# usage: input/output/cached token countscost = (usage.input_tokens * P_IN * (1 - usage.cache_hit_rate * CACHE_DISC)+ usage.output_tokens * P_OUT)log_service.write({"task_id": task_id, "variant": variant,"cost": cost, "latency_ms": usage.latency_ms,"success": usage.schema_valid,})
Write variant tags and cost details to logs, aggregate daily into dashboards and alerts. Archive raw requests and responses in object storage for recomputation and disputes.
4. Quality evaluation: do not let a single composite score decide
A blended “intelligence” score is one weighted mix; the weights may not match your product. Prefer layered evaluation:
- Capability slices: score code generation, tool use and multi-step planning, structured output, vision, and long documents separately.
- Business set first: a 100–300 example regression set from real traffic predicts production better than public leaderboards.
- Strict checks: schema validation for structured output; unit-test pass rate for code—avoid subjective drift from human grading.
- Look at the gap distribution, not only the mean: some dimensions may be tied, others not. Weight by business importance instead of the largest single gap.
5. Cost–quality frontier: one curve instead of a table
Plot candidates on capability score vs. cost per task. Keep only the points that are not dominated toward the lower-left—the efficient frontier. Only frontier options belong in A/B; dominated ones (more spend, worse score) can be dropped. The discussion shifts from “who is strongest” to “who is undominated under our budget and quality constraints.”
6. Launch is not the end: observe and govern
- Cost dashboard: split by product line, model version, and task type; alert on day-over-day change and budget thresholds.
- Quality regression: rerun the business set on every prompt or model change so cost cuts do not hide quality collapse.
- Fallback: automatic failover when the primary is rate-limited or times out; count switch events in cost.
- Periodic re-eval: models move fast; rerun evals and A/B on a fixed cadence so the choice stays current.
7. Common pitfalls
- Deciding from public leaderboards only, ignoring your traffic mix.
- Averages hiding the tail: a few very long-context requests can dominate cost.
- Ignoring that cache hit rate can swing hard when prompts change.
- Changing prompts or post-processing during A/B, so results cannot be attributed.
- Costing only successful calls and omitting retries and human fallback.
Closing
Selection is not “strongest” or “cheapest.” It is a measurable, repeatable, re-runnable engineering loop: write the cost formula, run same-environment, same-period A/B, decide with a frontier and sliced scores, and lock conclusions in logs, monitors, and archives. As upstream models change, the system can still converge to the best option under current constraints.
