Model Cost per Task: Moving Beyond Unit Pricing for LLM Selection

    Comparing LLM API prices per million tokens is not enough to control real spending. The actual cost of completing a task depends on pricing rules, the number of tokens consumed, and cache hit rates. This article breaks down the key billing dimensions—input/output pricing, long-context tiers, and cache pricing—and explains why output token efficiency often matters more than unit price. It also covers practical methods for improving cache hit rates, provides a Python cost calculation framework, and includes a selection evaluation checklist to help engineering teams make informed, budget-conscious model choices.

    Large language model (LLM) services typically bill input tokens and output tokens separately, with prices usually quoted per million tokens. Many teams compare only these two numbers when selecting a model. However, actual spending depends on three factors: the billing rules themselves, the number of tokens consumed to complete a given task, and the cost savings generated by context cache hits. Looking only at unit prices is like looking at a single item in a multi-part formula.

    Take a simple example. Two models have the same input price, but Model A generates three times as many output tokens as Model B on the same task. Model A’s output cost will clearly be higher. Conversely, a model with a higher unit price that produces more concise outputs may actually be cheaper on a per-task basis. The right comparison therefore is not “price per million tokens,” but “cost per completed task.”

    Breaking Down the Billing Dimensions

    1. Base Input and Output Pricing

    Most providers charge more for output tokens than input tokens. Output cost is directly tied to generation length, so managing output length is often the most direct lever for reducing cost.

    2. Long-Context Tiered Pricing

    Some services apply different price tiers depending on the input length of a single request. When a request crosses a certain threshold, the unit price may increase. When estimating costs, you need to clarify two things: whether the threshold applies to the total input length of the entire request, and whether the price increase applies to the entire request or only to the portion that exceeds the threshold. These details should be confirmed in the provider’s official billing documentation—never assume based on experience.

    Long-context scenarios commonly include code repository analysis, long-document QA, and multi-turn conversations. When designing such applications, it is advisable to estimate the distribution of input lengths per request in advance, and to determine whether frequent requests will fall into higher-priced tiers.

    3. Cache Pricing

    For repeatedly occurring prefix content—such as system prompts, fixed reference documents, and tool definitions—many services offer a cache read price that is significantly lower than the regular input price. When the cache is hit, the cost of repeatedly sending the same prefix drops substantially.

    Cache mechanisms also carry costs that need to be considered. Some providers charge an extra fee when writing to the cache, and cached entries have a limited time-to-live (TTL). Once expired, the content must be written again. The net benefit of caching therefore depends on how often the same prefix is reused. For content that is rarely reused, the write cost may offset the savings from cache reads.

    Output Token Efficiency

    Reasoning models generate a hidden chain-of-thought before producing a final answer. This intermediate content is billed as output tokens. As a result, “the answer looks short” does not mean the output is small. When evaluating a model, you should track the full output, including the reasoning trace and the final response.

    Two metrics are useful for measuring efficiency: the average number of output tokens required to complete a set of standard tasks, and the average cost per task. The first reflects whether the model is verbose; the second combines unit price and token count, linking directly to budget. Both metrics need to be examined together. If a model has a low unit price but produces several times more output tokens than another, its per-task cost may not actually be lower.

    Improving Cache Hit Rates

    Cache benefits depend heavily on request structure, and the application layer can be optimized to improve hit rates:

    • Place stable content near the beginning of the prompt, and move dynamic content—such as user questions or real-time data—toward the end, to increase the probability of prefix matching.
    • Keep fixed system instructions and tool definitions byte-identical across requests. Small differences like extra spaces or timestamps can invalidate the cache.
    • Manage conversation length. In multi-turn conversations, the growing history makes the prefix increasingly variable. Regularly trim the conversation history or replace it with a summary.
    • Measure the proportion of cached tokens relative to total input tokens, rather than merely noting whether a cache hit occurred at least once. That ratio is what reflects the real cost impact.

    A Per-Task Cost Model with Example Code

    Below is a general-purpose cost calculation framework. The price parameters in the code are sample values only and do not represent any provider’s real pricing. Replace them with the provider’s official billing data.

    1. from dataclasses import dataclass
    2. from typing import Optional
    3. @dataclass
    4. class Pricing:
    5. input_per_m: float # Price per million input tokens (cache miss)
    6. cached_input_per_m: float # Price per million input tokens (cache hit)
    7. output_per_m: float # Price per million output tokens (including reasoning tokens)
    8. long_ctx_threshold: Optional[int] = None # Long-context threshold (tokens)
    9. long_ctx_multiplier: float = 1.0 # Multiplier applied above the threshold (example assumption)
    10. def request_cost(p: Pricing, input_tokens: int, cached_tokens: int,
    11. output_tokens: int) -> float:
    12. """Calculate the cost of a single request, returned in USD."""
    13. if not 0 <= cached_tokens <= input_tokens:
    14. raise ValueError("Cached tokens must be between 0 and the total input tokens")
    15. mult = 1.0
    16. if p.long_ctx_threshold and input_tokens >= p.long_ctx_threshold:
    17. mult = p.long_ctx_multiplier
    18. uncached = input_tokens - cached_tokens
    19. cost = uncached * p.input_per_m + cached_tokens * p.cached_input_per_m
    20. cost += output_tokens * p.output_per_m
    21. return cost * mult / 1_000_000
    22. def cost_per_success(p: Pricing, requests: list[dict], successes: int) -> float:
    23. """
    24. requests: each entry contains input_tokens, cached_tokens, and output_tokens.
    25. successes: number of tasks completed successfully. Costs from retries and
    26. failed attempts are included in the total.
    27. """
    28. total = sum(
    29. request_cost(p, r["input_tokens"], r["cached_tokens"], r["output_tokens"])
    30. for r in requests
    31. )
    32. if successes == 0:
    33. raise ValueError("Number of successful tasks is zero, cannot compute unit cost")
    34. return total / successes

    Here is a walkthrough using example numbers. Suppose a task averages 20,000 input tokens per request, 15,000 of which are cache hits, and produces 8,000 output tokens. The task success rate is 80%. Using the sample prices above (input $10/M, cached input $1/M, output $50/M), the cost per request is:

    • Uncached input: 5,000 × 10 = 50,000
    • Cached input: 15,000 × 1 = 15,000
    • Output: 8,000 × 50 = 400,000

    The total is 465,000, divided by 1,000,000, which comes to approximately $0.465 per request. Factoring in the 80% success rate, the cost per successful task is about $0.58.

    If a second model has the same unit prices but generates 24,000 output tokens while other conditions stay the same, the cost per request is approximately $1.25—2.7 times the first model. This example illustrates that output length often has a much greater impact on cost than small differences in unit price.

    Evaluation Checklist for Model Selection

    1. Evaluate on your own task set rather than relying solely on general-purpose benchmarks. Benchmark tasks may diverge significantly from your actual business scenarios.
    2. Track the distribution of output tokens, focusing on both the average and high percentiles (e.g., P90). Long-tail requests often set the budget ceiling.
    3. Measure both cache hit rates and cache write costs to confirm whether the caching strategy is effective under real traffic patterns.
    4. Estimate the proportion of long-context requests and calculate the cost impact after crossing pricing thresholds.
    5. Include the cost of retries, failed requests, and manual review in the total cost.
    6. Consider latency and rate limits as well. Slower responses increase waiting time for users, and concurrency limits can reduce overall throughput.

    Conclusion

    A higher unit price does not necessarily mean a higher total cost. When a model is more efficient in generating outputs and cache utilization is strong, the cost per task can actually be lower. Teams should therefore establish a unified cost-per-task metric, monitor it continuously using their own data, and periodically revisit their model choices as billing rules and business traffic patterns evolve.