LLM Inference Costs: How to Convert Token Prices into Per-Task Costs

    Per-million-token pricing is the most visible number when comparing large language models, but it rarely reflects what you actually pay. This article explains why low unit prices can be misleading, breaks down the three variables that drive per-task cost, shows how to calculate cost per task and cost per correct result, and provides a reusable evaluation workflow with sample code for estimating real-world inference costs.

    LLM Inference Costs: How to Convert Token Prices into Per-Task Costs

    1. Low Unit Prices Don’t Necessarily Mean Low Costs

    LLM APIs are typically priced per million tokens, with separate rates for input and output. The first thing developers see is the unit price, but your actual bill reflects the total tokens consumed to complete a task multiplied by those unit prices. Two models whose prices differ by several times may not cost proportionally different amounts to complete the same task.

    This is easy to overlook when comparing models side by side. If a model generates more intermediate content during inference, or produces more verbose answers, its price advantage can be eroded by higher token consumption. That’s why you should first convert unit prices into per-task costs, and then weigh them against task quality.

    2. Three Variables That Determine Cost

    Per-task cost is driven by three variables:

    1. Unit price. Input and output are priced separately, and output tokens usually cost more than input tokens.
    2. Input token count. Made up of system instructions, prompts, conversation history, and any retrieved reference content. The longer the context, the higher the input cost.
    3. Output token count. This includes both the final user-facing answer and any internal reasoning the model generates along the way. Many APIs bill reasoning tokens as output tokens—check each provider’s billing documentation for the exact rules.

    The third variable is the most commonly underestimated. Given the same question, one model might produce a conclusion in a few hundred tokens directly, while another generates thousands of tokens of reasoning before delivering the same conclusion. The former uses far fewer output tokens than the latter. If you only look at unit prices, this difference is completely hidden.

    3. How to Calculate Per-Task Cost

    Estimate per-task cost with the following formula:

    1. Per-task cost = (average input tokens × input price + average output tokens × output price) ÷ 1,000,000

    The averages in the formula should come from real evaluation samples, not a single test. Task length, question difficulty, and output format all cause significant variation in token usage. In addition to the mean, record percentiles such as P50 and P90 to capture how long-tail tasks affect your budget.

    3.1 A Worked Example: Unit Price vs. Actual Cost

    The following numbers are for illustration only and do not represent real measurements from any model. Suppose Model A’s output price is one-third of Model B’s, but when completing the same type of task, Model A produces 1.6 times as many output tokens as Model B. Ignoring the input side, their relative output costs are:

    1. (1/3) × 1.6 ≈ 0.53

    Model A’s output cost is roughly half of Model B’s. The unit prices differ by three times, yet the actual cost gap is only about two times. The more tokens a model consumes, the more its price advantage gets offset. This is the mathematical reason why unit-price differences shrink when converted into per-task costs.

    3.2 Input Share Can Change the Conclusion

    For applications like retrieval-augmented Q&A or long-document analysis, input tokens often far outnumber output tokens. In that case, the input price carries much more weight, and a model that wins on output pricing may lose its edge. Always use your actual input/output ratio in the calculation—don’t borrow conclusions from other scenarios.

    4. Measuring Value with Cost per Correct Result

    Per-task cost alone isn’t enough to guide model selection. A cheap model with a low pass rate generates more rework, manual review, and retry requests, so its total cost may not be lower at all. A more useful metric is cost per correct result:

    1. Cost per correct result = per-task cost ÷ task pass rate

    A solution with a higher pass rate can end up with a lower cost per correct result than one with cheaper unit prices. Define the pass rate before running your evaluation—for example, based on automated validation, human scoring thresholds, or business metrics—and apply the same criteria consistently across all candidates.

    Latency is another dimension worth considering. Slow responses or frequent rate limiting stretch task completion times, increasing concurrency overhead and user wait costs. For interactive applications, latency may matter more than per-task cost.

    5. Building a Reusable Cost Evaluation Workflow

    Set up an evaluation process following the steps below, and make it repeatable as model versions and prices change.

    1. Fix your evaluation set. Cover common task types, including short samples, long samples, and edge cases—don’t rely only on easy questions.
    2. Log usage per sample. Read the input and output usage fields from API responses and save them alongside sample IDs for traceability. Most APIs return these fields in the response.
    3. Measure quality. Determine pass/fail for each sample via automated validation or human scoring, and compute the pass rate.
    4. Calculate costs. Apply the formulas above to get per-task cost and cost per correct result.
    5. Re-run periodically. Model updates or price changes can invalidate earlier conclusions, so re-run the evaluation when they occur.

    The sample code below shows how to run these calculations from evaluation records. The sample data and prices are placeholders—replace them with your real records and billing rates.

    1. # Example: estimate per-task cost and cost per correct result from evaluation records
    2. # Prices are per million tokens; values are placeholders—replace with your actual rates
    3. def cost_per_task(avg_in_tokens, avg_out_tokens, in_price, out_price):
    4. return (avg_in_tokens * in_price + avg_out_tokens * out_price) / 1_000_000
    5. def cost_per_correct(task_cost, pass_rate):
    6. if pass_rate <= 0:
    7. raise ValueError("Pass rate must be greater than 0")
    8. return task_cost / pass_rate
    9. # Sample data for demonstration only
    10. records = [
    11. {"in_tokens": 1200, "out_tokens": 3500, "passed": True},
    12. {"in_tokens": 900, "out_tokens": 6100, "passed": False},
    13. {"in_tokens": 1500, "out_tokens": 2800, "passed": True},
    14. ]
    15. avg_in = sum(r["in_tokens"] for r in records) / len(records)
    16. avg_out = sum(r["out_tokens"] for r in records) / len(records)
    17. pass_rate = sum(r["passed"] for r in records) / len(records)
    18. task_cost = cost_per_task(avg_in, avg_out, in_price=1.0, out_price=4.0)
    19. print(f"Per-task cost: {task_cost:.6f}")
    20. print(f"Cost per correct result: {cost_per_correct(task_cost, pass_rate):.6f}")

    6. Common Ways to Reduce Token Consumption

    To lower per-task cost, start by cutting wasted tokens rather than simply pushing for the lowest unit price.