LLM API Evaluation: Cost, Performance, and Model Selection
Most discussions about LLM APIs stop at "this model is too expensive," but per-token price is only one slice of total cost of ownership. This article shows how to model cost at the request, daily, and monthly level using input/output token pricing, how to build a multi-dimensional self-constructed evaluation set instead of trusting public leaderboards, how to weigh self-hosted open-source models against managed closed-source APIs, and which engineering practices — model tiering, context reduction and caching, output constraints, batch scheduling, and quantization — meaningfully change the bill. You get a practical selection checklist built around cost per unit of quality rather than headline price.
一、Evaluating a Model: Stop Looking at Price per Token Alone
In almost every conversation about putting LLMs into production, “that model is too expensive” is the most common verdict. The problem is that judging a model by its sticker price alone leads to one-sided conclusions. The price per call is just one facet of total cost of ownership (TCO). What actually drives the bill is the combined effect of call frequency, context length, retry strategy, and the engineering effort spent on manual tuning.
It also matters that newer model generations frequently deliver stronger capability at a lower unit price. As inference architectures improve, competition intensifies, and engineering efficiency rises, a newer model is not necessarily worse value than its predecessor. So rather than asking whether a model is expensive, ask three questions: What is the cost per unit of quality? Is total spend controllable while still meeting your business quality bar? Is the cost curve predictable as you scale? Answering those three is worth far more than a one-word verdict of “expensive.”
二、Understand Tokens First: Where the Cost Comes From
Cost analysis has to start with the billing unit: the token. A token is the smallest unit of text the model processes, and any text — Chinese, English, or source code — is split into tokens before it reaches the model. The industry convention is to price per million tokens, split into two categories: input tokens and output tokens.
A few points are worth internalizing:
- Input and output are usually priced asymmetrically. Decoding is computationally heavier than prefill for generative models, so output tokens generally cost more per unit than input tokens. Estimate the two separately instead of looking at a blended average.
- Context length scales cost directly. System prompts, conversation history, and documents assembled for retrieval-augmented generation (RAG) all count as input tokens. The longer the context, the higher the input cost of each call — and it stacks linearly as concurrency grows.
- Long-tail fields are easy to miss. Function calling, chain-of-thought output, and multi-turn tool orchestration all generate additional implicit token consumption.
A general-purpose function is enough to model the cost. The prices below are placeholders; replace them with the actual rates of whichever service you use:
def estimate_call_cost(input_tokens, output_tokens,in_price_per_m, out_price_per_m):"""Estimate the cost of a single call using per-million-token pricing(prices are placeholder values)"""in_cost = input_tokens / 1_000_000 * in_price_per_mout_cost = output_tokens / 1_000_000 * out_price_per_mreturn in_cost + out_cost# Example: ~3000 input tokens, ~800 output tokenscost = estimate_call_cost(3000, 800,in_price_per_m=4, out_price_per_m=12)print(f"Estimated cost per call: {cost:.4f}")# Extrapolate to a daily figuredaily_calls = 50000print(f"Estimated daily cost: {cost * daily_calls:.2f}")
Turning cost from a “unit price” into auditable numbers per request, per day, and per month is the first step toward a rational decision.
三、Performance Evaluation: Build a Multi-Dimensional Baseline, Not a Leaderboard Ranking
Public leaderboards are useful references, but they carry two well-known problems: data contamination creates incentives to overfit the benchmark, and the benchmark tasks often do not match the distribution of your real workload. The more reliable approach is to build your own evaluation set.
A practical evaluation matrix covers the following dimensions:
- Reasoning and math: multi-step logic problems, numerical calculation, constraint satisfaction.
- Long-context understanding: locating key information in long documents, synthesizing across sections, and resisting “lost in the middle” degradation.
- Coding: completion, refactoring, unit test generation, cross-file comprehension.
- Instruction following and format stability: whether the model reliably returns structured JSON and respects field constraints.
- Multilingual and localization: accuracy on Chinese semantics, dialects, and domain terminology.
- Engineering metrics: time to first token (TTFT), output tokens per second (throughput), error rate, and behavior under rate limiting.
A reusable evaluation skeleton looks roughly like this:
def run_eval(cases, model_client, judge):results = []for case in cases:resp = model_client.chat(case["prompt"])score = judge(case["expected"], resp) # rule-based check or LLM/human reviewresults.append({"id": case["id"],"score": score,"tokens": resp.usage.total_tokens,})avg_score = sum(r["score"] for r in results) / len(results)total_tokens = sum(r["tokens"] for r in results)return {"quality": avg_score, "tokens": total_tokens}
Once you have a quality score and a total token count, you can compute cost per unit of quality — a metric that tracks the business far more closely than unit price does.
四、Open Source vs. Closed Source: A Trade-Off About Control
Parameter counts in recent open-weight models keep climbing, and their performance is closing in on closed-source flagships quickly. That has put “build or call” back in the spotlight. Each route has trade-offs, and the right choice depends on your scenario:
- Closed-source managed service: works out of the box, no operations burden, elastic scaling — a good fit for fast validation and traffic with large swings. The cost is that data has to leave your environment, unit price grows linearly with volume, and you have less control.
- Open-source self-hosted: data stays inside your network, fine-tuning and deep customization are straightforward, and marginal cost drops at scale. The cost is that you have to run an inference cluster, absorb operations and tuning overhead, and meet a higher bar for team engineering capability.
On cloud platforms, these capabilities are generally offered as standard product categories — model inference services, container platforms, logging services, and monitoring and alerting. Baidu AI Cloud’s LLM-related services, for example, typically provide managed inference, elastic compute, and observability, which lets teams move flexibly between self-hosting and managed hosting. When deciding, weigh three things together — data compliance requirements, expected call volume, and your team’s operational maturity — rather than looking at model quality alone.
五、Engineering Practices for Cost Optimization
Choosing a model is where the real cost work begins. The following strategies routinely produce multiples of difference in spend:
- Model tiering and routing: send simple tasks (classification, extraction, short Q&A) to a small, light model and reserve the flagship for genuinely complex reasoning, with a routing layer splitting traffic by difficulty.
- Context trimming and caching: strip redundant system prompts and cache results for high-frequency prefixes, which cuts input tokens substantially.
- Output length control: explicit word or field constraints keep the model from generating long, irrelevant content.
- Batching and concurrency scheduling: where latency allows, use batch processing to improve throughput utilization.
- Quantization and inference acceleration: in self-hosted setups, quantization, distillation, and a suitable inference framework lower the cost per unit of compute.
def route_request(task):if task["complexity"] == "low":return light_model.chat(task["prompt"]) # light modelreturn flagship_model.chat(task["prompt"]) # flagship model
六、A Selection Checklist You Can Actually Execute
Taken together, an actionable selection checklist looks like this:
- Build your own evaluation set from real business data, producing a “quality score + token volume” pair;
- Use cost per unit of quality and total monthly cost as the core decision metrics;
- Define your data compliance boundary, then decide between self-hosting open weights or managed calls;
- Complete routing, caching, and output constraints before launch;
- Set up cost monitoring and alerting so abnormal call volumes trigger early warnings.
Conclusion
Deciding whether an LLM is “worth it” really comes down to one question: can you hit your business goals reliably at a controllable cost? Moving your attention from a single unit price to cost structure, multi-dimensional performance, and engineering optimization is what makes the decision rational and sustainable. Models will keep iterating, but this evaluation methodology stays reusable — and that is the most dependable footing when the technology keeps moving.
