LLM Selection: Token Efficiency and Long-Running Task Evaluation
How should you choose a large language model for real workloads? This article explains why unit task cost matters more than list price, covers four evaluation dimensions—token consumption per task, pricing structure and caching, long-running task stability, and output quality—and provides a reproducible benchmarking workflow with sample code for measuring cost per completed task.
LLM Selection: Token Efficiency and Long-Running Task Evaluation
Why You Should Evaluate Unit Task Cost, Not Unit Price
A common approach to model selection is comparing prices on a rate sheet. But list price is only part of the picture. When completing the same task, different models can consume several times more tokens than others. A model with a lower unit price may require more reasoning turns, longer context, and more retries, which can result in a higher final bill. A more meaningful metric is unit task cost: the total expense of completing a clearly defined task.
This is especially evident in long-running task scenarios. Reading files, calling tools, modifying code, and running tests all re-send historical context to the model with each step, so input tokens accumulate over rounds.
Dimension 1: Token Consumption per Task
Start by fixing the task—for example, “add unit tests to a small project and make all test cases pass.” Then record, during execution, the uncached input tokens, cached input tokens, output tokens, and the number of API calls.
Key metrics to track:
- Total input tokens: the sum of inputs across all requests, including repeatedly sent historical context.
- Total output tokens: everything the model generates, including any billed thinking or reasoning tokens.
- Number of calls: tool calls and retries both amplify consumption.
- Task completion rate: incomplete tasks should be excluded from cost comparisons; otherwise the comparison is meaningless.
A common pitfall is looking only at the length of a single response. A short single response does not mean the overall task consumed fewer tokens.
Dimension 2: Pricing Structure and Cached Input
Most LLM services price requests in three parts: uncached input, cached (cache-hit) input, and output. Cached input is typically cheaper per token, but discount levels, cache eligibility conditions, and cache retention times vary across providers. In long-running tasks, historical context repeats frequently, so cache hit rate often determines the final cost.
Total cost can be estimated with this formula:
Total cost = uncached input tokens × uncached input price + cached input tokens × cached input price + output tokens × output price
Note that some services charge an extra fee for writing to the cache, so cached input is not always cheaper than regular input. Do not judge by output price or standard input price alone. The most reliable approach is to plug real task logs into the formula rather than relying on theoretical estimates.
Dimension 3: Stability in Long-Running Tasks
Long-running tasks last longer and involve many requests, so network interruptions, timeouts, and rate limiting all affect outcomes. During evaluation, record:
- Request failure rate and failure types;
- Whether execution can resume after retries;
- Whether task state can be resumed from a checkpoint after an interruption.
Engineering practices that reduce these risks:
- Break tasks into independently verifiable steps;
- Save intermediate artifacts after each step for easy recovery;
- Use exponential backoff for retries with a maximum retry limit;
- Summarize and compress historical context to prevent unbounded context growth.
Dimension 4: Reasoning Quality and Output Accuracy
High token efficiency does not guarantee reliable results. Evaluation should cover:
- Whether code or configuration changes pass existing tests;
- Whether file reads and writes are accurate, with no unintended edits or omissions;
- Whether intermediate conclusions are correctly referenced in multi-step reasoning;
- Whether output follows the specified format constraints.
Combine automated verification with manual spot checks. Run the same task multiple times and observe the variance in results rather than drawing conclusions from a single successful run.
Building a Reproducible Evaluation Pipeline
The key to reliable benchmarking is controlling variables: a fixed task set, fixed prompts, a consistent tool environment, and complete logging. Below is a simplified cost calculation example. The price parameters are placeholders only—replace them with your provider’s official prices.
from dataclasses import dataclass@dataclassclass Usage:uncached_input: intcached_input: intoutput: int# Placeholder prices, unit: currency per million tokens, replace with actual pricesPRICE = {"uncached_input": 1.0, "cached_input": 0.2, "output": 4.0}def task_cost(u: Usage) -> float:return (u.uncached_input * PRICE["uncached_input"]+ u.cached_input * PRICE["cached_input"]+ u.output * PRICE["output"]) / 1_000_000def summarize(runs: list[Usage], completed: list[bool]) -> dict:done = [r for r, ok in zip(runs, completed) if ok]total = sum(task_cost(r) for r in done)return {"completion_rate": len(done) / len(runs),"avg_cost_per_completed_task": total / len(done) if done else None,}
In practice, run the same task set multiple times on each candidate model, then calculate completion rate and average cost per successfully completed task. Cost metrics must always be read alongside completion rate—looking at unit price or cost alone leads to one-sided conclusions.
Common Pitfalls
- Ranking models by unit price instead of cost.
- Judging by demo scenarios while ignoring real long-running tasks.
- Overlooking the extra consumption caused by failed requests and retries.
- Drawing conclusions from a single run.
- Ignoring the impact of caching strategy on cost.
Practical Recommendations
Start with a small task set to establish a baseline, then scale up gradually. Keep your evaluation scripts under version control, and re-run them whenever a new model is released or prices change. Document the test conditions, sample size, and statistical criteria behind your selection conclusions so they can be reviewed later and reused across your team.
