From Token Price to Cost Per Task: How to Evaluate LLM Inference Efficiency

    Evaluating the true cost of Large Language Model (LLM) inference requires looking beyond the price per million tokens. This article explores how to calculate and optimize the cost per task, explaining the impact of reasoning tokens, benchmarking strategies using Pareto frontiers, and practical steps for building a robust evaluation workflow. By understanding the relationship between token usage, model capability, and latency, developers and architects can make more informed decisions when selecting and deploying LLMs.

    1. Low Token Price Does Not Mean Low Total Cost

    LLM services are typically billed based on token usage, with separate pricing for input and output tokens. When selecting a model, many people first compare the price per million tokens. While this serves as a useful reference, it only answers the question “how much does each token cost?” rather than “how much does it cost to complete a specific task?”

    Two models might have a several-fold difference in their unit price. However, if the cheaper model needs to generate significantly more intermediate content to arrive at an answer, the final cost per task may end up being very similar. Therefore, when evaluating the cost of an inference service, you must consider the unit price, token consumption, and the task completion method holistically.

    2. Core Concepts and Calculation Methods

    1. Token Price: The price per million input and output tokens published by the service provider. Output prices are typically higher than input prices.
    2. Input Token Count: Consists of the prompt, context, historical conversation, and retrieved content (e.g., from RAG).
    3. Output Token Count: Includes the final answer as well as any content generated by the model during the reasoning process. Most services that bill by output tokens include reasoning tokens in the output count, meaning these intermediate steps directly impact your bill.
    4. Cost Per Task: The average cost to complete a full task, serving as the fundamental unit for cost evaluation.

    The formula for calculating the cost per task is as follows:

    Cost Per Task = Input Tokens / 1,000,000 × Input Price + Output Tokens / 1,000,000 × Output Price

    Represented in code:

    1. def task_cost(in_tokens: int, out_tokens: int,
    2. in_price: float, out_price: float) -> float:
    3. """Calculate the cost of a single task. Prices are in USD per million tokens."""
    4. return in_tokens / 1e6 * in_price + out_tokens / 1e6 * out_price

    3. A Hypothetical Comparison Example

    The following figures are illustrative and used solely to explain the calculation method; they do not represent any real-world service measurements.

    Assume Model A has an input price of $1 per million tokens and an output price of $4 per million tokens. The average task requires 2,000 input tokens and 50,000 output tokens (including reasoning content). Model B has an input price of $2 per million tokens and an output price of $8 per million tokens, but the average task only outputs 20,000 tokens.

    • Model A Cost Per Task: 2,000 / 1e6 × 1 + 50,000 / 1e6 × 4 = 0.002 + 0.200 = $0.202
    • Model B Cost Per Task: 2,000 / 1e6 × 2 + 20,000 / 1e6 × 8 = 0.004 + 0.160 = $0.164

    Model B’s output price is twice that of Model A, yet its cost per task is approximately 19% lower. Output efficiency has reversed their cost ranking. This demonstrates that comparing only token prices can lead to incorrect conclusions.

    4. Why Reasoning Tokens Change the Cost Structure

    Reasoning-oriented models generate intermediate reasoning steps before providing the final answer. While this mechanism improves accuracy on complex tasks, it brings three direct consequences:

    1. The output token count increases, driving up the cost per task.
    2. The generation length increases, extending response latency and increasing both user wait time and system resource occupancy.
    3. Variance in consumption across different tasks increases, leading to higher cost volatility.

    When measuring inference efficiency, you should focus on the “average number of tokens consumed to achieve a target accuracy rate.” Lower consumption means higher efficiency. Keep in mind that averages can mask long-tail distributions. A few complex tasks might consume several times more tokens than average tasks. Therefore, you should also track the median (P50) and the 90th percentile (P90) to observe the distribution of high-consumption samples.

    5. Aligning Capability and Cost

    Looking solely at aggregate benchmark scores cannot tell you whether a model is worth deploying. A more rational approach is to observe three dimensions simultaneously: overall capability score, cost per task, and latency per task.

    Within these dimensions, you can use the concept of a Pareto frontier to filter candidate models: among models with the same score, choose the one with the lowest cost; among models with the same cost, choose the one with the highest score. Options that are comprehensively outperformed by other models can be eliminated immediately.

    Another practical metric is the cost per correct task. This merges quality and expenditure into a single number, making horizontal comparisons easier:

    1. def cost_per_correct(results: list[dict]) -> float:
    2. """Calculate the average cost in USD for each correct task."""
    3. total_cost = sum(r["cost"] for r in results)
    4. correct = sum(1 for r in results if r["correct"])
    5. return total_cost / correct if correct else float("inf")

    Note that the cost here includes the expenditure on failed tasks. Failed API calls are still billed, so you cannot only account for the cost of successful tasks.

    6. Building Your Own Evaluation Workflow

    1. Build a representative task set: Break down tasks based on real-world business logic, covering simple, medium, and complex categories. Each category should contain an adequate number of samples to prevent conclusions from relying on isolated examples.
    2. Standardize calling conditions: Using identical system prompts, sampling temperatures, maximum output lengths, and retry strategies is a prerequisite for fair horizontal comparison. Different conditions yield non-comparable results.
    3. Log metrics per call: Every API call should log the input token count, output token count, reasoning token count (if returned by the service), latency, whether a retry occurred, and whether the result was correct.
    4. Calculate aggregate metrics: Include average cost per task, P90 cost, accuracy rate, and cost per correct task.
    5. Ensure consistent grading: When comparing different models, the task content and grading rules must be identical. Mixing samples of varying difficulty levels renders the comparison meaningless.

    7. Common Pitfalls

    • Pitfall 1: Only looking at parameter size. Total parameters reflect a model’s capacity, and activated parameters affect the scale of a single forward pass. However, actual cost also depends on deployment methods, batching efficiency, hardware utilization, and service pricing strategies. Fewer parameters do not necessarily mean lower costs, nor do they necessarily mean weaker capabilities.
    • Pitfall 2: Only looking at averages. The average cost per task might be very low, but if there is a significant volume of tasks with extremely long outputs, your budget will still be exceeded. Check high-percentile costs before going live.
    • Pitfall 3: Ignoring the input side. Long contexts, concatenated RAG results, and multi-turn chat histories all inflate the input token count. If the service offers cache pricing, the cache hit rate will also significantly affect the actual fee.
    • Pitfall 4: Ignoring retries. Retries caused by timeouts or formatting errors incur duplicate billing. In high-concurrency scenarios, the retry ratio can become a primary variable in your overall costs.

    8. Practical Deployment Recommendations

    1. Tiered routing: Assign models based on task difficulty. Route simple tasks to models with low inference overhead, and reserve high-intensity reasoning models strictly for complex tasks.
    2. Set output limits and reasoning budgets: Prevent runaway tasks by enforcing maximum output lengths, keeping individual task costs under control.
    3. Establish cost monitoring: Break down token consumption by functional module, user segment, and task type. This allows you to quickly locate the source of anomalies when they occur.
    4. Regular re-evaluation: After a service version update, both performance and token consumption may change. You should re-run the evaluation suite with every update rather than relying on outdated conclusions.
    5. Calculate Total Cost of Ownership (TCO): In on-premise or cloud-based deployment scenarios, the costs of compute resources, object storage, logging services, and monitoring alerts should all be factored in. The total cost of an inference service goes far beyond the API bill.

    Conclusion: The key to evaluating LLM costs is shifting the focus from “how much per token” to “how much per task” and “how many correct tasks per dollar.” By measuring capability, token efficiency, and latency simultaneously during the selection process, you can arrive at reliable and actionable conclusions.