Calculating LLM Costs: From Token Pricing to Cost per Task
This article explains how to evaluate large language model costs beyond headline token prices. It covers the four components of total cost, trade-offs among billing models, a step-by-step method for calculating cost per task and cost per successful task, selection criteria, and a vendor lock-in checklist.
Calculating LLM Costs: From Token Pricing to Cost per Task
When teams choose a large language model, the first step is often to compare the published price per million tokens across vendors. That number is useful, but it covers only part of the bill. Engineering changes, team operations, and later migration costs do not appear on the price list. Real workload patterns also change inference usage. Together, these factors can create a large budget gap.
This article provides a practical costing method. The first part explains what total cost includes. The second part compares the cost characteristics of three billing models. The third part gives formulas and steps for calculating cost per task. The fourth part explains selection criteria, and the fifth part provides a migration lock-in checklist. All prices in this article are illustrative assumptions; replace them with the latest vendor quotes before making decisions.
1. The Four Components of Total Cost
To evaluate the true cost of an LLM service, cover at least four categories of spending.
1.1 Inference call costs
This is the most direct part of the bill, charged separately for input tokens and output tokens. Pay attention to the following points.
- Input and output prices: Most vendors charge more for output than for input, but the exact ratio depends on the official price list and varies widely by model.
- Cache discounts: Repeated requests with the same prefix may hit the cache, and the cached portion may be charged at a lower price. Confirm with the vendor whether caching is supported, the discount rate, and the cache validity period.
- Batch discounts: For offline tasks that are not latency-sensitive, asynchronous batch APIs may offer discounts. Whether you can use them depends on whether the business allows delayed responses.
- Context length: Multi-turn conversations keep accumulating history, so input tokens grow with each turn. Without truncation or summarization, the cost per call will gradually rise.
- Retries and failed requests: Timeout retries generate additional calls. Check the terms of service to determine whether failed requests are billed.
- Reasoning tokens for reasoning models: Some models output a reasoning process. Confirm separately whether these tokens are counted as billed output.
Parameters to collect include average daily requests, average input tokens, average output tokens, cache hit rate, batch-processing share, and retry rate.
1.2 Engineering adaptation costs
This spending does not appear on the bill, but it continues throughout the project lifecycle. It mainly includes API integration and SDK wrappers, prompt tuning, output format validation, evaluation set construction, and regression testing after model switches.
Parameters to collect include engineering person-days, cost per person-day, evaluation set size, and regression hours per model switch. Record one-time investment and ongoing investment separately so they can be amortized later.
1.3 Operations and governance costs
After launch, the service still requires ongoing investment in monitoring, log retention, content safety auditing, quota and rate-limit management, key rotation, cost alerts, and compliance reviews. These tasks are often handled by the existing team and are easy to overlook, but they consume significant labor.
Parameters to collect include monitoring and log storage costs, on-call hours, compliance review frequency, and manual effort for security audits.
1.4 Migration lock-in costs
Migration lock-in refers to the cost of moving the business to another model or platform. Common cases include incompatible APIs that require rewriting, prompts that perform worse on a new model and need retuning, fine-tuning assets that cannot be exported, data and logs that can only be stored on the vendor side, and data deletion and exit costs when a contract ends.
Parameters to collect include estimated hours for one model switch, service downtime or degradation losses during migration, and data export costs at exit.
2. Comparison of Three Billing Models
The following table summarizes the main cost characteristics of the three models. The content is general; specific terms are governed by the vendor contract.
| Cost item | Pay-as-you-go | Subscription | Private deployment | Parameters to collect | Risk notes |
|---|---|---|---|---|---|
| Billing unit | Number of tokens per call | Fixed monthly or annual fee with usage allowance | Hardware purchase or rental, plus electricity and operations | Daily token volume, peak concurrency, budget cycle | Pay-as-you-go bills fluctuate at peak |
| Fixed cost | Basically none | Yes, related to whether the allowance is fully used | High, including GPUs, data center, and depreciation | Contract terms, hardware quotes | Unused subscription allowance is waste |
| Peak capacity | Depends on vendor rate limits and quotas | Constrained by plan ceiling | Constrained by owned hardware capacity | Peak QPS, concurrency | Rate limits may affect business peaks |
| Low-load cost | Falls with usage | Fixed spending remains unchanged | Fixed spending remains unchanged | Usage during off-peak periods | Private deployment has low utilization at low load |
| Operations and staffing | Relatively low | Relatively low | Relatively high; dedicated maintenance required | Operations staffing cost | Staffing costs are often underestimated |
| Migration lock-in | Depends on API compatibility | Difficult to switch during the contract term | Lower, but model updates must be handled in-house | Contract term, API specification | Switching during the contract term may incur penalties |
| Data compliance | Data leaves the domain and must be assessed | Same as pay-as-you-go | Data can remain local | Data classification, compliance requirements | Out-of-domain restrictions may determine the choice |
Use the following judgments as a reference during selection. When load fluctuates widely and the peak-to-trough difference is large, pay-as-you-go is usually more flexible, but check the rate-limit rules at peak. When load is stable and usage is predictable, a subscription or reserved capacity may be more cost-effective; the key is to confirm the allowance ceiling and overage price. When data cannot leave the domain, or daily usage is extremely high, private deployment is worth evaluating, but hardware depreciation, electricity, and operations staffing must all be included in the cost.
3. Steps for Calculating Cost per Task
A single token price cannot directly compare the value of different services. A more reliable metric is cost per task: the average spend to complete one full business action. For example, one customer service Q&A, one contract summary, or one product description generation can each be treated as one task unit.
Step 1: Define the task
Define the task unit in the business and list the number of model calls each task contains. If a task requires classification first and then generation, N is 2.
Step 2: Collect workload parameters
Collect data for at least one week, preferably including one business peak cycle. Record the following parameters:
- N: average number of calls per task
- T_in: average number of input tokens per call
- T_out: average number of output tokens per call
- h: cache hit rate
- r_retry: retry rate
- P_in: input price, in CNY per million tokens
- P_cache: price for the cached portion, in CNY per million tokens
- P_out: output price, in CNY per million tokens
- M: monthly task volume
Step 3: Calculate inference cost
First calculate the effective input price. If the service does not support caching, set h to 0.
Effective input price = P_in × (1 − h) + P_cache × h
Inference cost per task = (T_in × effective input price + T_out × P_out) × N × (1 + r_retry) ÷ 1,000,000
If a batch API is used, multiply the price of the corresponding portion by (1 − batch discount rate) before plugging it into the calculation.
Step 4: Amortize non-inference costs
Engineering adaptation and migration lock-in are one-time or phased investments and need to be amortized over the usage period. Operations and governance are ongoing expenses and are counted monthly.
Monthly amortized engineering cost = one-time engineering investment ÷ amortization months
Total cost per task = inference cost per task + (monthly amortized engineering cost + monthly operations and governance cost) ÷ M
Step 5: Calculate cost per successful task
If different services produce different output quality, comparing cost alone will be biased. Use the same evaluation set to measure the task pass rate, then calculate the cost per successful task.
Cost per successful task = total cost per task ÷ task pass rate
Example calculation
The following values are assumptions for demonstrating the calculation process only and do not represent any vendor’s real quote.
Assume the following: each task makes 1 call (N = 1), T_in = 3000, T_out = 800, cache hit rate h = 40%, cache price is 20% of the input price, P_in = 2 CNY per million tokens, P_out = 8 CNY per million tokens, retry rate r_retry = 5%, monthly task volume M = 100,000, one-time engineering investment is 30 person-days at 1,500 CNY per person-day, amortized over 12 months, and monthly operations and governance cost is 3,000 CNY.
First, calculate the effective input price. The cache price is 2 × 0.2 = 0.4 CNY per million tokens. Effective input price = 2 × 0.6 + 0.4 × 0.4 = 1.36 CNY per million tokens.
Second, calculate the inference cost. The input portion is 3000 × 1.36 ÷ 1,000,000 = 0.00408 CNY. The output portion is 800 × 8 ÷ 1,000,000 = 0.0064 CNY. The total is 0.01048 CNY; after accounting for a 5% retry rate, it is 0.01048 × 1.05 ≈ 0.011 CNY.
Third, calculate the monthly inference total. 0.011 × 100,000 = 1,100 CNY.
Fourth, calculate amortization and operations. The one-time engineering investment is 30 × 1,500 = 45,000 CNY. Amortized over 12 months, that is 3,750 CNY per month. Monthly operations and governance cost is 3,000 CNY.
Fifth, calculate the total cost per task. Monthly fixed-related spending is 3,750 + 3,000 = 6,750 CNY, or 0.0675 CNY per task. Total cost per task ≈ 0.011 + 0.0675 = 0.0785 CNY.
This example shows that inference calls account for only about 14%, while the remaining 86% comes from engineering and operations. A selection method that compares only token prices will miss most of the cost.
Break-even point for private deployment
To determine whether private deployment is cost-effective, calculate the break-even monthly task volume.
Break-even monthly task volume = private deployment monthly fixed cost ÷ (pay-as-you-go cost per task − private deployment variable cost per task)
Here, private deployment monthly fixed cost includes hardware depreciation, data center and electricity, and operations staffing. Private deployment variable cost per task includes electricity consumption per task and necessary inference service overhead. The formula assumes comparable output quality between the two options, which should be verified with an evaluation set.
4. Selection Criteria
- Use cost per successful task as the primary ranking metric, not token price.
- Use the same evaluation set for candidate services and compare cost at the same quality level.
- Record P95 latency, availability commitments, rate limits, and quota ceilings at the same time; these factors affect user experience and substitutability.
- Recalculate with real peak and average workloads. Growing context length and higher retry rates will significantly change the result.
- Check price validity periods, promotion discount deadlines, and model retirement notice periods. Changes in these terms directly change cost.
- Include migration lock-in risk in the selection score instead of handling it after the contract is signed.
5. Migration Lock-in Checklist
Confirm the following items one by one before signing.
- Is the API compatible with mainstream common formats, and is it easy to replace with another service?
- Do prompts and output parsing logic depend on a vendor-specific feature?
- Can fine-tuning data, fine-tuned models, or adapters be exported?
- Can call logs, evaluation sets, and vector indexes be exported in common formats?
- Are rate limits, quotas, and service-level commitments written into the contract?
- How long is the notice period for model retirement or version deprecation?
- What is the time limit and method for data deletion after contract termination?
- Is a backup model prepared, and has at least one switch drill been completed?
- Have the estimated hours and downtime losses for one switch been calculated?
6. Summary
Calculating LLM costs requires four steps: list all cost items, collect your own workload parameters, calculate cost per task, and then compare cost per successful task using the same evaluation set. Pay-as-you-go, subscription, and private deployment each fit different scenarios. The final conclusion depends on workload shape, data compliance requirements, and the team’s operations capability. Running the formulas above with your own data will be more informative than any token price table.
