LLM Selection in Practice: Balancing Price, Capability, and Agent Scenarios
Selecting the right large language model (LLM) involves more than just comparing unit prices. This article explores how to evaluate LLMs by understanding the sources of cost discrepancies, identifying hard constraints, calculating cost per task, benchmarking with real business tasks, and assessing specific requirements for Agent scenarios. By following a structured evaluation and implementation approach, developers can make data-driven decisions that optimize both performance and cost.
1. Where Do Price Differences Come From?
Whether reading files, generating code, or calling external tools, the cost per turn can vary significantly across different models. These cost differences primarily stem from three sources: varying unit prices for input and output, billing for the reasoning/thinking process in the output, and the number of retries required due to unstable task performance. A lower unit price does not guarantee a lower total cost. If a model fails to complete the task correctly on the first attempt and requires multiple rounds of correction, the overall cost may actually be higher.
Therefore, model selection must answer two questions: Can a cheaper model complete the task in a single attempt? Can a more expensive model reduce the need for rework? Simply comparing unit prices cannot answer these questions.
2. Confirm Hard Constraints Before Comparing Prices
Before calculating costs, eliminate candidates that cannot meet your business requirements. The following five constraints are the most common:
- Input Modalities: Support for text, images, and video varies. Batch image-text tasks and direct video understanding have different requirements. When direct video processing is needed, filter for candidates that support video input first.
- Context Window: The window size determines how much information can be processed at once. However, a larger window does not guarantee reliable information retrieval and citation within long documents; this requires empirical testing.
- Output Budget: The maximum generation length per response determines whether a model can output complete code or long reports in a single pass. Generation-heavy tasks should prioritize checking this metric.
- Reasoning Mechanism: Some models allow toggling the reasoning process on or off. Reasoning content typically consumes the generation budget. If reasoning and answering share the same limit, you must allocate space for both.
- Billing Metrics: Different providers may charge separately for input, output, cache hits, or reasoning content, and billing units may differ. Standardize the metrics before making comparisons.
Additionally, in some implementations, the input and the current generation share the same context window. If the input fills the entire window, the remaining space may be insufficient for an equally long output. Such limitations should be considered in advance when designing prompts.
3. Convert Unit Price to Cost Per Task
Cost accounting should be based on the “cost to complete a task” rather than the unit price per request. The following code example provides two basic functions. Price parameters should align with the billing units used by the provider.
def cost_per_attempt(input_tokens, output_tokens, reasoning_tokens,price_in, price_out):# price_in, price_out are the price per million tokens, consistent with the billing unitbilled_output = output_tokens + reasoning_tokensreturn (input_tokens * price_in + billed_output * price_out) / 1_000_000def effective_cost(attempt_cost, first_pass_rate):# Approximate effective cost using the first-pass success rate, assuming independent attemptsif not 0 < first_pass_rate <= 1:raise ValueError("first_pass_rate must be between (0, 1]")return attempt_cost / first_pass_rate
Consider a hypothetical example to illustrate this formula. Candidate A has an attempt cost of 1 (baseline) and a first-pass success rate of 50%, resulting in an effective cost of 2. Candidate B has an attempt cost of 3 and a first-pass success rate of 90%, resulting in an effective cost of approximately 3.33. Under these assumptions, the cheaper Candidate A is still more cost-effective. However, if Candidate B’s success rate increases to 100%, the conclusion reverses. Therefore, ranking must rely on empirically tested success rates, not intuition.
4. Benchmark with the Same Business Tasks
Specification sheets explain what a model can do, not how well it does it. The basic steps for benchmarking are as follows:
- Extract Samples: Draw 50 to 200 samples from real business scenarios, covering both simple and difficult cases, while retaining a few edge cases.
- Define Acceptance Criteria: Each sample must have automatically verifiable criteria. For example, code must pass unit tests, structured output must pass schema validation, and extracted image fields must exactly match the annotations.
- Fix Variables: Keep prompts, sampling parameters, and tool definitions consistent to prevent factors outside the comparison from affecting the results.
- Record Metrics: Record the token count for input, output, and reasoning, as well as the latency for each call.
- Repeat Runs: Run the same sample multiple times to track the success rate and variance range.
Below is an example of a benchmarking framework. The model calling function needs to be implemented by the user according to their specific integration method.
import jsonimport timedef run_benchmark(models, cases, call_model, check, out_path="benchmark.json"):report = {}for model in models:rows = []for case in cases:start = time.time()resp = call_model(model, case["prompt"], case.get("files"))rows.append({"case_id": case["id"],"passed": check(case, resp["text"]),"input_tokens": resp["usage"]["input"],"output_tokens": resp["usage"]["output"],"reasoning_tokens": resp["usage"].get("reasoning", 0),"latency_s": round(time.time() - start, 2),})report[model] = rowswith open(out_path, "w", encoding="utf-8") as f:json.dump(report, f, ensure_ascii=False, indent=2)return report
The resulting report can be directly used to calculate each model’s success rate, average token consumption, and effective cost, transforming selection from subjective judgment into objective calculation.
5. Evaluation Focus for Agent Scenarios
Agent tasks require the model to call tools across multiple rounds, and errors in earlier steps propagate to subsequent ones. Therefore, evaluation for Agent scenarios should focus on the following four aspects:
- Tool Calling Stability: Do the parameters conform to the API definition? Are required fields frequently omitted? Does it attempt to call non-existent tools?
- Long-Chain State Retention: After multiple rounds of interaction, does the model still remember the constraints established early on?
- Error Recovery: Upon receiving an error from a tool, can the model correct the parameters based on the error message instead of repeating the same mistake?
- Termination Conditions: Upon task completion, can the model stop promptly to avoid ineffective loops?
Engineering-wise, two protective measures should be implemented. First, set a maximum step limit to prevent infinite looping. Second, establish a budget ceiling per task; abort and log if exceeded. These two measures are often more direct for cost control than simply choosing a cheaper model.
Labels like “high-performance” or “lightweight” in model names only indicate product positioning and do not prove the success rate of Agent tasks. The basis for judgment should be the empirical results from the benchmark suite.
6. Recommended Implementation Order
- Establish a cost baseline using high-frequency, structured tasks. Start by selecting a candidate with a low unit price and acceptable stability as your starting point.
- For budget-sensitive tasks requiring longer generation, include candidates with larger output budgets for comparison.
- For tasks requiring direct video understanding, filter candidates that support video input separately; do not mix them with text-only tasks during evaluation.
- For complex Agent tasks, use the same benchmark suite to determine the final solution. Rank based on effective cost, not unit price.
- Continuously monitor success rates and token consumption post-launch. Re-run the benchmark suite when providers adjust prices or release new versions.
Specifications and pricing change with version updates. Before making a decision, refer to the provider’s latest official documentation and retain the raw data from each evaluation for future reference.
