Beyond Token Pricing: How to Calculate LLM Cost per Task

    When evaluating Large Language Model (LLM) APIs, comparing token prices alone often leads to inaccurate cost assessments. This article explains why businesses should focus on the cost per complete task rather than just token pricing. It details the formula for calculating task costs, examines the four key variables that influence these costs—pricing structure, reasoning tokens, model scale, and quality alignment—and provides an example calculation. Additionally, it offers practical engineering recommendations for cost optimization and highlights common misconceptions in LLM cost evaluation.

    1. Why Token Pricing Alone Can Mislead

    LLM APIs are typically priced per million tokens. Pricing tables are easy to find and often used for direct comparisons. However, business systems bear the full cost of completing an entire task. A single task may involve multiple API calls, and each call involves three types of tokens: input, reasoning (thinking), and output. The price difference per token can be partially or entirely offset by differences in token usage.

    Therefore, model selection discussions should shift from token pricing to cost per task, which represents the total API expenditure required to complete a full business task.

    2. The Formula for Calculating Cost per Task

    For a single model call, the cost can be expressed as:

    Cost per call = (Input tokens × Input price + Output tokens × Output price) ÷ 1,000,000

    Note that the output tokens should include those generated during the reasoning process. In most pricing models, reasoning tokens are billed at the same output rate as the final response. Consequently, longer reasoning chains lead to higher costs.

    If a task requires multiple rounds of calls, the total task cost is the sum of the costs of each call. In engineering practice, this is typically estimated using the average of a batch of representative samples:

    1. def call_cost(input_tokens, output_tokens, in_price, out_price):
    2. """Price unit: USD / Million Tokens"""
    3. return (input_tokens * in_price + output_tokens * out_price) / 1_000_000
    4. def task_cost(calls):
    5. # Each item in calls is (Input Tokens, Output Tokens, Input Price, Output Price)
    6. return sum(call_cost(*c) for c in calls)
    7. def average_task_cost(samples):
    8. # samples is a list of tasks, where each task is a list of calls
    9. return sum(task_cost(s) for s in samples) / len(samples)

    3. Four Variables Affecting Cost per Task

    1. Input and Output Pricing Structure

    A common pricing structure is that the output price is significantly higher than the input price. Input tokens are cheaper, meaning the cost of long-context scenarios is primarily driven by input scale. Output tokens are more expensive, meaning costs can easily be amplified when generating long texts or performing extended reasoning. Before selecting a model, you should analyze the ratio of input to output in your business workflows to determine which pricing metric demands more attention.

    2. Reasoning Tokens and Output Length

    For the same query, different models or different settings within the same model may employ varying depths of reasoning. More extensive reasoning might improve accuracy, but it also increases the number of output tokens. This is a classic trade-off between quality and cost. During evaluation, record both the average output token count and percentiles (such as P90), because a small number of long-tail tasks often consume the majority of the budget.

    3. Model Scale and Activated Parameters

    In Mixture of Experts (MoE) architectures, the total parameter count determines the scale of knowledge the model can hold, while the activated parameter count dictates the parameters actually involved in the forward pass for each inference. Fewer activated parameters usually mean lower computational requirements. However, this is only one factor in the service cost. The provider’s hardware utilization, batching strategies, and pricing models equally influence the final price. Therefore, total and activated parameter counts cannot be directly converted into user-side costs; they should only be used as auxiliary information for understanding the cost structure.

    4. Quality Alignment

    Cost comparisons are only meaningful when quality levels are similar. If two solutions achieve comparable scores in comprehensive evaluations, the one with the lower unit cost is more valuable. If there is a significant gap in scores, you should compare quality before comparing cost. A comprehensive evaluation index is usually derived by weighting multiple sub-benchmarks; before comparing, ensure that the test sets, prompt templates, and scoring criteria are consistent across all parties.

    4. Example Calculation

    The following figures are hypothetical values for demonstration purposes and do not represent any actual product.

    Suppose there are two solutions, A and B, used to perform the same type of task:

    • Solution A: Input price $1.0/Million Tokens, Output price $4.0/Million Tokens. Per task: 20K input tokens, 40K output tokens (including reasoning).
    • Solution B: Input price $2.5/Million Tokens, Output price $10.0/Million Tokens. Per task: 20K input tokens, 20K output tokens.

    Solution A cost per task: 20K × 1.0 / Million + 40K × 4.0 / Million = $0.02 + $0.16 = $0.18

    Solution B cost per task: 20K × 2.5 / Million + 20K × 10.0 / Million = $0.05 + $0.20 = $0.25

    Solution B’s output price is 2.5 times that of Solution A, but its cost per task is only about 39% higher. This is because Solution B generates only half the output tokens of Solution A. If you only look at the token price, you will overestimate the gap between the two. If you only look at the output token count, you will ignore the impact of the unit price. Both factors must be calculated together.

    5. Engineering Best Practices

    1. Build a representative evaluation sample set: Extract samples from real business operations and record quality metrics, input tokens, output tokens, latency, and cost. The samples should cover both simple and complex tasks, avoiding testing only easy cases.
    2. Control unnecessary outputs: Reduce redundant text through structured outputs, clear formatting requirements for answers, and sensible maximum output length limits. The maximum output length should be set according to the task distribution to avoid truncating critical content.
    3. Route by task difficulty: Assign simple tasks to lower-cost models and escalate complex tasks to more capable models. Routing rules should be calibrated based on historical data and reviewed regularly.
    4. Compress input context: Summarize historical conversations and retain only the fragments relevant to the current task. Deduplicate and rerank retrieval results to reduce costs caused by irrelevant inputs.
    5. Build a cost monitoring dashboard: Integrate cost per task, token distribution, and retry counts into your logging service. Set monitoring and alerting thresholds to detect abnormal long outputs or circular calls promptly.

    6. Common Misconceptions

    • Comparing only unit prices: Ignoring task usage easily leads to one-sided conclusions.
    • Comparing only parameter scales: There is no simple linear relationship between total/activated parameters and cost or quality.
    • Ignoring failed retries: Retries caused by formatting errors or substandard results increase actual expenditure and should be factored into the cost per task.
    • Using averages instead of distributions: Average output token counts can mask long-tail tasks; you should also monitor the median and high percentiles.
    • Ignoring the timeliness of prices and versions: API prices and model versions update frequently; comparison conclusions should note the statistical date and model version.

    The core of model selection is placing quality, usage, and unit price into the same cost model. Unit price dictates the cost of each token, usage dictates how many tokens a task requires, and quality dictates whether those tokens are worth the expense. Missing any one of these three will likely cause your conclusions to deviate from reality.