LLM API Cost Calculation: Monthly Cost Formulas and Tiered Model Selection
This article explains how LLM API bills are calculated, including input and output token pricing, retry and cache effects, and a monthly cost formula. It also covers where low-cost models come from and their limits, how to compare cost per successful task, tiered routing, common pricing mistakes, a pre-launch checklist, and how to estimate whether self-hosting is worthwhile.
1. Token-Based Billing: How the Bill Is Actually Calculated
LLM APIs are generally priced per million tokens, with input (prompt) and output (completion) billed separately. Input includes the system prompt, conversation history, and retrieved documents. Output is the text generated by the model. The two unit prices are often different, and output is usually several times more expensive than input because generating each output token requires a full forward pass, while input can be processed in parallel batches.
The cost of a single call can be calculated as:
Single-call cost = input tokens ÷ 1,000,000 × input price + output tokens ÷ 1,000,000 × output price
Monthly cost is the single-call cost multiplied by the number of monthly calls, with retries included:
Monthly cost = monthly calls × average single-call cost × (1 + retry rate)
Here, the retry rate equals the number of requests that must be reissued divided by total requests. Whether failed requests are billed depends on the vendor’s rules. Some vendors bill for tokens already generated, while others do not bill at all. Check this before selecting a vendor; otherwise, retries can quietly inflate the bill.
If a request hits the cache, the calculation needs one more step. The cached portion of input is billed at the cache price, while the uncached portion is still billed at the regular input price. Caching usually requires a highly consistent request prefix, so fixed system prompts and reference documents should be placed at the very beginning of the request to improve hit rates.
The following example uses a set of hypothetical numbers. Assume the input price is USD 2 per million tokens and the output price is USD 8 per million tokens. These numbers are only for demonstration and do not represent any vendor’s quote. In a customer service scenario, each call averages 1,500 input tokens and 300 output tokens, with 100,000 calls per month and a 5% retry rate.
Single-call cost = 1,500 ÷ 1,000,000 × 2 + 300 ÷ 1,000,000 × 8 = 0.003 + 0.0024 = USD 0.0054
Monthly cost = 100,000 × 0.0054 × 1.05 ≈ USD 567
In this example, input cost accounts for a larger share. If output length doubles, the output portion of the cost also doubles. The actual share of the two token types depends on your business request patterns.
2. Where Low Cost Comes From, and Its Boundaries
Cost reduction mainly comes from three areas: model architecture and inference optimization, vendors’ tiered product strategies, and deployment choices enabled by open-weight models. Understanding these sources helps determine whether a low price is reliable.
Common architecture-level methods include the following.
- Mixture of Experts (MoE): only some parameters are activated per token, reducing computation per call. However, all expert parameters still need to fit in VRAM, so the barrier to self-deployment is not low.
- Grouped Query Attention (GQA): reduces the number of key-value heads and lowers KV cache usage. It usually has a small impact on quality, but it must be adopted during training.
- KV cache compression: relieves VRAM pressure in long contexts. Over-compression may lose distant details, so long-document tasks require dedicated evaluation.
- Speculative decoding: a small model drafts first, and a large model verifies in batches. The benefit depends on the draft acceptance rate and varies greatly by task.
- Quantization (INT8, FP8): reduces VRAM and bandwidth requirements and improves throughput. Precision loss varies by model and task and must be validated before launch.
When these methods are combined, the cost per unit of intelligence generally declines. A low-cost model is not necessarily poor quality; the key question is whether it can complete your target task. A low-cost model may perform consistently on classification, extraction, and rewriting, but it may degrade noticeably on multi-step reasoning or long-document synthesis.
The boundaries also need to be clear. Low-cost models are suitable for tasks with high concurrency, higher fault tolerance, and automatic evaluation. For scenarios with strong compliance requirements, high latency requirements, or a high cost per error, keep a stronger model and add human review. Beyond price, data residency, service stability, rate limits, and SLA terms are also selection constraints.
3. The Core of Selection: Compare Cost for the Same Task
Comparing only the listed price per million tokens can easily lead to the wrong conclusion. A more reliable approach is to compare the total cost of completing the same task, namely cost per successful task:
Cost per successful task = total monthly cost ÷ number of tasks that pass acceptance
Acceptance criteria need to be defined in advance. They can be based on manual sample pass rates, rule validation, or comparison with reference answers. Run candidate models on the same sample set and record the following metrics:
- Task accuracy: pass rate calculated according to acceptance criteria.
- Retry rate: proportion of requests that need to be reissued.
- P95 latency: the response-time ceiling for 95% of requests, which reflects user experience better than the average.
- Average output length: directly determines the output portion of cost.
- Cost per successful task: the final cost after combining the factors above.
- Long-context degradation: the drop in accuracy when input becomes longer.
Evaluation samples should ideally number at least several hundred and should cover difficult cases from real business scenarios, rather than only easy questions.
4. Tiered Routing: Use Cheap Models Where They Fit
The idea of tiered routing is to allocate models according to task difficulty. Most business requests do not need a flagship model; only a small number of complex requests do. A common three-tier structure is as follows.
- Tier 1: lightweight models for classification, keyword extraction, format conversion, and other highly deterministic tasks.
- Tier 2: balanced models for most generation and question-answering tasks.
- Tier 3: flagship models for complex reasoning, high-risk content, and escalation requests after the first two tiers fail.
Routing rules can be based on task type, input length, business priority, or confidence signals and validation results from model output. A practical approach is to have the lower-tier model answer first, then escalate to a higher-tier model if validation fails or confidence is below a threshold. This keeps average cost close to that of the lower-tier model while preserving higher-tier quality on difficult samples.
Escalation creates extra calls, so the additional tokens and latency from escalation must be included in monthly cost and P95 latency. Routing thresholds should be tuned repeatedly on the evaluation set, not set by intuition.
5. Common Mistakes and a Price Verification Checklist
Common mistakes include the following.
- Comparing only the listed price per million tokens while ignoring output length and call volume.
- Ignoring retries, or not knowing whether failed requests are billed.
- Assuming all requests can hit the cache without fixing the request prefix.
- Using outdated prices. Price tables change, and calculation sheets should note the data date.
- Ignoring currency, taxes, and exchange-rate conversion.
- Looking only at price while ignoring rate limits, SLAs, and data residency terms.
Before launch, verify the following checklist.
- Record the price source page and publication date, and reconfirm before each decision.
- Confirm the three unit prices separately: input, output, and cache hit.
- Confirm whether retries are billed and whether rate limits can handle peak traffic.
- Confirm the availability commitments and data processing scope in the service terms.
6. Is Self-Hosting Worthwhile?
Open-weight models can be self-hosted, but the cost structure differs from pay-as-you-go APIs. The monthly cost of self-hosting is roughly: GPU hours × hourly price × running hours, plus operations, storage, and network costs.
The break-even point can be estimated as follows. First calculate the fixed monthly cost of self-hosting, then divide it by the amount saved per call compared with the pay-as-you-go API to get the required number of monthly calls. If actual call volume is far below this number, pay-as-you-go billing is more cost-effective. Self-hosting also requires labor for scaling, failure recovery, and model upgrades, and these costs are often underestimated.
