Model Selection by Cost per Task: A Practical Evaluation Method

    Comparing list prices alone does not show what it costs to finish a real task. This article explains how unit price, token usage, and first-pass acceptance rate combine into cost per task, then covers billing categories, quality and latency metrics, a reproducible evaluation workflow, tiered routing, and ongoing cost controls.

    1. Why unit price is not the real cost

    When teams choose a large language model, the first instinct is often to compare price lists. Input, output, and cached-token prices per million tokens are the basis of the bill, but they only describe how much one token costs. They do not describe how much it costs to finish a piece of work.

    In real workloads, the cost of a task depends on three factors:

    1. Unit price: the rate for each billing category.
    2. Usage: the input and output tokens actually consumed to complete the task.
    3. Effective yield: the share of tasks that pass acceptance on the first attempt. If the model needs several rounds of correction, or a person has to redo the work, failed requests still count toward cost.

    Consider two models. Model A has a lower unit price, but its answers are verbose, it produces about twice as many output tokens as model B, and it often needs a retry. Model B costs more per token, yet it returns a usable result in one pass. Ranked by unit price, A looks cheaper. Ranked by total cost per task, B may be the better deal. Selection should therefore shift from unit price to cost per task.

    2. How billing structure affects cost

    Most major model APIs split billing into several categories. Understanding each one helps control spend.

    2.1 Input and output

    Input tokens include system instructions, conversation history, retrieved material, and the user question. Output tokens are what the model generates. In most pricing schemes, output tokens cost more than input tokens, so limiting output length is often more effective than compressing the input. Common practices include:

    • Stating a clear length or format limit in the instructions.
    • Using structured output, such as JSON, and dropping unrelated explanation.
    • Returning only a label or a score when the task needs a judgment, not a narrative.

    2.2 Cached input

    When many requests share the same prefix—a fixed system prompt, a long technical document, or tool definitions—some providers price that prefix as cached input, at a rate well below ordinary input. Cache savings depend on two conditions:

    • The prefix is long enough and stays in a stable position.
    • The gap between requests is short enough for the cache to hit.

    In practice, put reusable content at the start of the prompt and variable user content at the end. Also measure cache hit rate; otherwise you cannot tell whether the change is working.

    2.3 Context length

    A longer context means more input tokens on every request. Sending the full conversation history makes cost grow linearly with the number of turns. Common controls are a sliding window of recent turns, summarizing older history, and retrieving only the passages relevant to the current question.

    3. Metrics centered on cost per task

    A practical evaluation uses three metrics.

    Metric 1: Cost per task

    Cost per task is the total spend to complete a set of tasks, divided by the number of tasks that pass acceptance. Include the cost of failed requests and retries. Leaving them out understates the real cost.

    The formula is:

    Cost per task = sum of all request costs / number of tasks that pass acceptance

    Metric 2: Quality score

    A quality score measures how usable the output is. Use one of the following, or combine them:

    • Rule checks: whether the format is valid, required fields are present, or code passes tests.
    • Model-assisted scoring: a separate evaluator model scores outputs against a rubric, with a human review of a sample.
    • Human scoring: domain experts grade outputs. This fits high-risk work.

    Metric 3: Latency and stability

    Latency covers time to first token and time to the full response. Stability covers timeout rate, error rate, and output variance. For interactive products, latency directly affects user experience. For batch jobs, it mainly affects throughput and schedule.

    Trading off cost and quality

    Plot cost per task on the horizontal axis and quality score on the vertical axis to draw a cost–quality curve. Models toward the upper left are cheaper and higher quality. Models on the Pareto frontier are all worth considering. Models that exceed the budget should be excluded even if their quality is the highest.

    4. A reproducible evaluation workflow

    Step 1: Build a representative test set

    The test set should come from real work and be stratified by difficulty:

    • Easy tasks: format conversion, keyword extraction, classification.
    • Medium tasks: question answering over source material, summarization.
    • Hard tasks: multi-step reasoning, complex code changes, analysis that requires judgment.

    Each tier needs enough samples. Testing only easy cases produces an optimistic result. Refresh the set regularly so models are not over-tuned to old data.

    Step 2: Hold variables fixed and log usage

    When comparing models, keep the prompt, temperature, tool configuration, and input samples the same. For every request, record input tokens, cached input tokens, output tokens, and elapsed time, and tie those records to a task ID.

    Step 3: Score automatically, then sample for human review

    Automate anything a rule can decide, such as validating JSON or running unit tests. For the rest, an evaluator model can assign scores. Draw a random sample for human review to check whether that evaluator is itself reliable.

    Step 4: Compute the metrics and write the report

    The example below shows how to compute cost per task from request logs. The prices only illustrate the calculation. Replace them with the official prices of the service you use.

    1. def cost_per_task(records, prices, passed_flags):
    2. """
    3. records: list of usage records, one per request
    4. prices: unit prices by model tier, per million tokens
    5. passed_flags: boolean list of whether each task passed acceptance
    6. """
    7. total_cost = 0.0
    8. for r in records:
    9. p = prices[r["tier"]]
    10. total_cost += (
    11. r["input_tokens"] / 1e6 * p["input"]
    12. + r["cached_tokens"] / 1e6 * p["cached"]
    13. + r["output_tokens"] / 1e6 * p["output"]
    14. )
    15. passed = sum(passed_flags)
    16. if passed == 0:
    17. return float("inf")
    18. return total_cost / passed
    19. prices = {
    20. "large": {"input": 8.0, "cached": 0.4, "output": 40.0}, # example values
    21. "small": {"input": 2.0, "cached": 0.1, "output": 10.0}, # example values
    22. }

    Note that input_tokens here means ordinary input that was not served from cache. If the logged input total already includes the cached portion, subtract it first. Otherwise that portion is billed twice.

    5. Tiered selection and routing

    Few products need only one model. A more common pattern is to assign models by task difficulty:

    • Hard tasks use a more capable model. Accept a higher unit price in exchange for a higher pass rate.
    • Everyday traffic uses the model with the best overall cost-quality balance, covering most of the volume.
    • Simple tasks use a smaller model or plain rules, which lowers marginal cost.

    Routing can use these signals:

    1. A task-type label set by the upstream application.
    2. Simple features of input length and complexity.
    3. Confidence or validation of the first result, with a retry on a stronger model if it fails.

    The third option is usually the most effective, but it must not escalate without limit. Set a maximum number of retries. After that, hand the task to a person or return a fallback result.

    6. Engineering practices

    6.1 Cost monitoring

    Record spend by feature, tenant, model, and environment, and roll the logs up into a monitoring dashboard. Track daily spend, the trend in cost per task, cache hit rate, and the share of abnormal requests. When spend spikes, alerts should reach the owner promptly.

    6.2 Budgets and rate limits

    Set a monthly budget and a daily cap for each product line. Near the threshold, automatically fall back to a lower-cost model or pause nonessential features. Rate-limit user-facing endpoints so abnormal traffic cannot run the bill out of control.

    6.3 Periodic re-evaluation

    Model updates, price changes, and shifts in production data all change the best choice. Re-run the same test set every quarter, or after a major release, and update the routing rules. Do not freeze a one-time selection indefinitely.

    6.4 Prompts and cache working together

    Keep stable system instructions and knowledge snippets in the prefix, and put dynamic content at the end. Constrain the output format and cut unnecessary explanation. Cache summaries of long documents that appear repeatedly. These changes often lower cost per task without switching models.

    7. Conclusion and recommendations

    The core question in model selection is how much it finally costs to finish one task, and whether the quality meets the requirement. Unit price is one input. It is not a decision by itself. A practical sequence is:

    1. List the core business tasks and build a stratified test set.
    2. Log usage on every request, then compute cost per task and a quality score.
    3. Plot the cost–quality curve and shortlist candidate models.
    4. Design tiered routing and a retry cap so extreme cases stay within budget.
    5. Put monitoring, budgets, and periodic re-evaluation in place.

    With this method, a team can tell quickly whether a capability change or a price change calls for a new plan, instead of relying on a single price comparison.