Beyond Token Pricing: A Cost Accounting Method for LLM Tasks
This article explains why comparing unit prices of LLM tokens is insufficient for estimating actual expenses. It introduces a single-task cost accounting model, analyzes the main factors affecting token efficiency, and outlines a comprehensive framework for model selection based on quality, cost, latency, and stability. Additionally, it provides engineering practices for cost observability, tiered routing, and common pitfalls to avoid when evaluating LLM costs.
1. Unit Price Does Not Equal Cost
Large language model (LLM) services typically bill by token, distinguishing between input and output tokens, with unit prices expressed per million tokens. Many teams directly compare unit prices during model selection, which seems straightforward. However, what a business actually pays is the total tokens consumed to complete a task; the unit price is just one factor of the cost.
Suppose the output unit price of one model is half that of another. If the cheaper model requires more than twice the output tokens to complete the same task, its task cost will actually be higher. Comparing unit prices ignores task-level consumption and therefore cannot be used directly as the sole basis for model selection.
2. The Single-Task Cost Accounting Model
The cost of a single task can be estimated using the following formula:
Task Cost = (Average Input Tokens × Input Price + Average Output Tokens × Output Price) ÷ 1,000,000
The terms are defined as follows:
- Average Input Tokens: Includes all input content such as system prompts, conversation history, and retrieved context (RAG).
- Average Output Tokens: Includes the model’s final answer, as well as the internal reasoning tokens generated by reasoning models before answering. Reasoning tokens are also billed as output tokens and are often a primary source of cost inflation.
- Input Price and Output Price: Entered according to the provider’s listed price per million tokens; the two are usually different.
The formula above only covers model invocation costs. If the task also involves tool calls, failed retries, or human review, these costs must also be factored into the total.
Here is a demonstration using hypothetical values. The figures are for illustration only and do not represent any real model’s performance. Assume a task averages 2,000 input tokens:
- Model A: Input price $1/million tokens, output price $4/million tokens, average output 8,000 tokens. The single-task cost is (2,000 × 1 + 8,000 × 4) ÷ 1,000,000 = $0.034.
- Model B: Input price $2/million tokens, output price $8/million tokens, average output 3,000 tokens. The single-task cost is (2,000 × 2 + 3,000 × 8) ÷ 1,000,000 = $0.028.
Model B’s unit price is twice that of Model A, but because its output length is only about one-third of Model A’s, its single-task cost is actually about 18% lower. Model selection should be based on single-task cost, not unit price.
During accounting, a simple illustrative code snippet can be used for batch estimation:
def estimate_task_cost(input_tokens, output_tokens, price_in, price_out):# Unit price: amount per million tokensreturn (input_tokens * price_in + output_tokens * price_out) / 1_000_000def average_task_cost(samples, price_in, price_out):costs = [estimate_task_cost(s["input_tokens"], s["output_tokens"],price_in, price_out) for s in samples]return sum(costs) / len(costs)
Samples should be drawn from real business traffic, not manually selected typical examples.
3. Key Factors Affecting Token Efficiency
The token consumption of the same model can vary significantly across different tasks. The main influencing factors include:
- Task Complexity: Tasks requiring multi-step reasoning, cross-document synthesis, or code debugging naturally require longer internal reasoning and longer outputs.
- Reasoning Intensity Settings: Some models offer reasoning intensity or thinking budget options; higher levels typically lead to longer internal reasoning. Using high settings for simple tasks will cause unnecessary overhead.
- Output Format Constraints: Requiring structured output, limiting word counts, or forbidding irrelevant explanations can significantly reduce output tokens.
- Prompt Design: When instructions are vague, models tend to elaborate unnecessarily. Clear output templates improve stability and compress output length.
- Retries and Self-Correction: Repeated calls after a task failure will linearly amplify costs. Retry rates need to be tracked and included in the accounting.
The unit price of output tokens is usually higher than that of input tokens, so output length often has a greater impact on total cost than input length. Only compressing the prompt without controlling the output usually yields limited savings.
4. A Comprehensive Evaluation Framework for Model Selection
Selecting a model based solely on a single benchmark score can be misleading. It is recommended to compare models across four dimensions: quality, cost, latency, and stability.
- Quality: Compare using the same prompts and scoring criteria on an evaluation set closely aligned with your own business. Scoring systems differ across different benchmarks, so direct horizontal comparisons require caution.
- Cost: Calculate single-task costs based on the input/output distribution of real business traffic, and record P90 percentiles to prevent averages from masking long-tail tasks.
- Latency: Pay attention to both Time to First Token (TTFT) and overall completion time. The longer the reasoning, the longer the user waits, which is particularly impactful in interactive scenarios.
- Stability: Includes result variance across multiple runs with the same input, API error rates, and rate limiting frequency.
You can plot quality and single-task cost on a 2D scatter plot. Retain only the candidates that offer the highest quality at an equivalent cost or the lowest cost at an equivalent quality. The boundary formed by these points is called the Pareto frontier. Solutions falling within the frontier can typically be eliminated.
It is also worth noting that there is no direct conversion relationship between a model’s parameter scale and its service cost. Service cost depends on deployment hardware, batching strategies, inference optimization techniques, and provider pricing. Judging unit price or single-task cost based solely on parameter scale often leads to unreliable conclusions.
5. Engineering Implementation: Establishing Cost Observability
After selection, you must continuously monitor live costs, otherwise model version updates or changes in business traffic will quietly alter the cost structure. It is recommended to complete the following four tasks:
- Log Call Details: Save the task type, model version, input tokens, output tokens, duration, and success status for every call.
- Aggregate by Task Type: Calculate the average single-task cost and P90 cost for each task type to identify the most resource-intensive tasks.
- Set Budget Alerts: Automatically notify the person in charge when the daily total cost or single-task cost exceeds a threshold, including the corresponding task type and model version.
- Implement Tiered Routing: Route simple tasks to low-cost models, and complex or high-risk tasks to high-quality models. Before routing rules go live, offline evaluations must confirm that the quality loss is within an acceptable range.
The illustrative logic for tiered routing is as follows:
def route(task):if task.risk_level == "high":return "quality_model"if task.complexity == "low":return "budget_model"return "standard_model"
Common methods to reduce output tokens include:
- Setting a maximum output parameter, though you need to monitor the truncation rate to avoid incomplete answers.
- Requiring a fixed structure for returns, such as outputting only JSON fields or bulleted conclusions.
- Caching request results for identical inputs to avoid duplicate billing.
- Summarizing or truncating long contexts to reduce input tokens.
6. Common Pitfalls
- Pitfall 1: Low unit price always saves money. The unit price only indicates the price per token; task cost also depends on the number of tokens required to complete the task.
- Pitfall 2: Equal benchmark scores mean equal capabilities. Comprehensive scores are averaged across multiple task types, and performance in your specific business scenario may vary greatly.
- Pitfall 3: Smaller parameter scale means lower cost. Service cost is determined jointly by deployment methods and service pricing; parameter scale is only one indirect factor.
- Pitfall 4: Only looking at average consumption. A small number of extremely long tasks can account for the majority of costs. You need to observe percentiles and long-tail distributions simultaneously.
7. Implementation Recommendations
- Conduct small-scale comparative tests using real business samples, covering different task types as well as peak and off-peak hours, before deciding whether to switch models.
- Place quality metrics and single-task costs on the same dashboard to avoid focusing on only one metric.
- Re-run the core evaluation set and update cost accounting after every model version update or pricing adjustment.
- Set review cycles for selection conclusions, as model versions and service pricing change rapidly.
