Choosing Large Language Models on a Limited Budget: Evaluation and Practice

    This article explains how teams with limited budgets can select and evaluate large language models. It argues that the key question is whether the cost of each completed task matches the required capability. The article covers total cost beyond token prices, task-level metrics for quality, latency, token usage and failure cost, testing methods for long-context and agent tasks, execution-based code evaluation, and a gradual rollout process for turning evaluation results into engineering decisions.

    1. The Core Question: Whether Cost per Task Matches Capability

    In budget-constrained projects, developers rarely need to ask whether a model is strong enough in general. The more useful question is which combination of model capabilities gives the best value for a given task distribution, quality threshold, and budget limit. Model selection should account for at least four types of cost: input and output token fees, retry and failure compensation costs, extra context costs from tool calls, and manual review and business risk costs. Looking only at the price of a single call often overlooks repeated reads in long-context tasks, multi-turn tool calls in agent workflows, and the testing and repair work that follows code generation.

    Selection should therefore rely on an internal benchmark set rather than external leaderboards or single-point tests. Start by splitting tasks by business scenario, such as long-document understanding, code completion and repair, structured information extraction, multi-turn tool calling, and writing and polishing. Define a quality threshold and a cost ceiling for each scenario. Then compare candidate approaches on the Pareto frontier across quality, latency, and cost. For cost-sensitive teams, a more practical strategy is tiered routing. Use more capable models for high-value tasks, and use lower-cost models or rule-based solutions for low-risk tasks. Keep calibrating the routing through gradual traffic rollout.

    2. Evaluation Metrics: Look Beyond Accuracy to Latency, Tokens, and Failure Cost

    Accuracy should be defined for each task, not only as a score on a uniform multiple-choice test. For extraction tasks, measure field-level accuracy and the pass rate for complete records. For code tasks, measure compilation pass rate, unit test pass rate, patch correctness, and regression risk. For agent tasks, measure tool selection accuracy, parameter correctness, multi-turn completion rate, and error recovery ability. Use the final business pass rate as the primary metric, and use the accuracy of intermediate steps as a diagnostic metric.

    Record latency as P50, P95, P99, and end-to-end time. Average latency can hide long-tail delays, and agent tasks are often affected by multiple rounds of calls. Token usage should distinguish input tokens, output tokens, reasoning tokens, tool return results, and cache-hit portions. You can estimate cost with the following general formula:

    1. Cost per task =
    2. (input tokens × input price
    3. + output tokens × output price
    4. + tool/retrieval context tokens × corresponding price) / number of tasks
    5. + retry cost
    6. + manual review cost
    7. + allocated share of business losses from failures

    Cost per thousand calls is only a reference. It must be considered together with task success rate and manual intervention rate. A solution with a lower per-call price but a higher retry rate can cost more in total. An evaluation report should include four tables covering quality, latency, token usage, and cost. It should also state the test set size, the task distribution, and confidence intervals, so that small samples do not lead to overconfident conclusions.

    3. Long-Context and Agent Capabilities: A Larger Window Does Not Guarantee Effective Use

    Long-context ability should be tested not only for whether content fits in the window, but also for whether the model uses that content reliably. Design three types of tests. The first is retrieval tasks where key information appears at the beginning, middle, and end of a document. The second is tasks where multiple documents contain conflicting information and the model must choose between them. The third is long-chain tasks that require summarizing and citing content across chapters. Watch for whether the model misses information in the middle of the context, confuses similar entities, or fails to keep format constraints in long inputs.

    Break agent ability into tool selection, parameter generation, call order, error handling, and termination conditions. In multi-turn tool use, common problems include repeated calls, parameter type errors, failure to retry after a timeout, and failure to fall back after an error. During evaluation, record structured logs for each tool call. Calculate task completion rate, average number of turns, invalid call rate, and recovery success rate. In production systems, set a maximum number of turns, timeouts, idempotency keys, and manual fallback. These controls prevent agents from looping endlessly on abnormal paths.

    4. Code Evaluation: Judge by Executable Results

    Code ability should not be judged only by whether a generated snippet looks like code. A more reliable process works as follows. Given repository context and a task description, the model generates a patch. The patch then goes through compilation or static checks, relevant unit tests, a security scan, and regression testing. Metrics include compilation pass rate, test pass rate, first-attempt fix success rate, average number of repair rounds, and the share of patches that introduce regressions. For completion scenarios, add acceptance rate, edit distance, and developer acceptance rate. For repair scenarios, focus on how minimal and maintainable the patch is.

    An illustrative evaluation script looks like this:

    1. for task in benchmark_tasks:
    2. context = load_repo_context(task)
    3. patch = model.generate(task.instruction, context)
    4. if not compile(patch): record("compile_fail"); continue
    5. if not run_tests(patch): record("test_fail"); continue
    6. if security_scan(patch): record("risk"); continue
    7. record("pass", latency, token_usage, cost)

    The key to this process is automated replay and version comparison. After each model or prompt change, rerun the fixed benchmark set. This prevents a common mistake: a solution that performs well on a single demo but is unstable across batch tasks.

    5. Cost Modeling and Gradual Rollout: Turning Evaluation Results into Engineering Decisions

    After offline evaluation, run a small-traffic gradual rollout. During this stage, run the old and new solutions side by side. Record quality spot checks, latency, token usage, cost, and failure types. For long-context tasks, use summary caching, segmented retrieval, and result reuse to reduce repeated token consumption. For agent tasks, use tool result caching, failure fallback, and turn limits. For code tasks, run static checks first to filter out invalid cases before calling the model, which reduces wasted generation.

    Capacity planning should include peak concurrency, long-tail latency, and rate-limiting strategies. General cloud services such as monitoring and alerting, log services, and object storage can store evaluation samples, call logs, and result snapshots. However, the core of selection remains the internal benchmark set and the cost model. The final recommendation is not to base decisions on a single external evaluation. Instead, build a continuous loop: scenario benchmark set, offline evaluation, cost modeling, gradual rollout validation, and ongoing regression testing. Only when accuracy, latency, token usage, cost, and failure impact appear in the same decision table can a budget-constrained team identify the technical solution that fits its business.