How to Estimate LLM API Costs in 2026: Formula & Worked Example
Before you ship an LLM feature, you should be able to estimate what it will cost — and the math is simpler than it looks. LLM pricing is just two numbers (input and output price per million tokens) multiplied by how many tokens you send and receive. This guide gives you the formula, explains how token counting works, walks a real monthly estimate end to end, shows a modeled cost table across models, and flags the assumptions that make estimates wrong.
The cost formula
LLM pricing is two numbers — an input price and an output price per million tokens — multiplied by how many tokens you send and receive:
cost = (input_tokens / 1,000,000) × input_price
+ (output_tokens / 1,000,000) × output_price
That's the whole model. Everything else — monthly bills, comparisons, optimization — is this formula applied at scale. The two prices are separate because output usually costs 2-8x more than input, so a workload's shape (input-heavy vs output-heavy) matters as much as its size.
How token counting works
Tokens are sub-word chunks produced by the model's tokenizer. Useful rules of thumb for English:
- ~4 characters ≈ 1 token (so ~750 words ≈ 1,000 tokens).
- Both directions count — your prompt, system message, and any retrieved context are input tokens; the model's reply is output tokens.
- It varies — code, rare words, and non-English text use more tokens per character; run the actual tokenizer on representative samples when you need precision.
From per-request to per-month
Scale the formula by volume:
- Estimate a typical request: input tokens (system + context + user) and expected output tokens.
- Multiply each by your monthly request count to get monthly input and output token totals.
- Apply the model's two prices. Add a margin (10-30%) for retries, longer-than-average requests, and accumulating multi-turn history.
A worked estimate
A support chatbot handling 200,000 conversations/month, each ~6 turns:
- Per conversation: ~200 input tokens/turn × 6 + a 1,000-token system prompt resent each turn ≈ ~7,200 input; ~150 output tokens/turn × 6 ≈ ~900 output.
- Monthly totals: ~7,200 × 200,000 ≈ 1.44B input; ~900 × 200,000 ≈ 180M output.
- On GPT-5 mini ($0.25/$2): 1,440 × $0.25 + 180 × $2 ≈ $360 + $360 = ~$720/month.
- On DeepSeek V3.2 ($0.23/$0.34): 1,440 × $0.23 + 180 × $0.34 ≈ $331 + $61 = ~$392/month.
Notice the system prompt resent every turn dominates input — caching it (see cost-cutting) would slash this estimate. That's the value of estimating before building: you spot the cost driver early.
Modeled cost across models
For reference, here are five standard workloads priced across four models with the formula — useful as a sanity-check anchor for your own estimates:
| Monthly workload | Claude Opus 4.7 | GPT-5.4 | Gemini 3.1 Pro | DeepSeek V3.2 |
|---|---|---|---|---|
| Support chatbot | $500 | $280 | $224 | $13.3 |
| RAG / knowledge base | $1,500 | $800 | $640 | $52.8 |
| Coding agent | $1,025 | $575 | $460 | $26.9 |
| Batch extraction | $950 | $495 | $396 | $37.2 |
| Content generation | $1,100 | $650 | $520 | $18.2 |
Assumptions that matter
- Workload shape — RAG is input-heavy (cheap-input models win); content generation is output-heavy (output price dominates). Estimate per workload, not as one average.
- Context reuse — a resent system prompt or retrieved context inflates input fast; decide early whether you'll cache it.
- Output length — the easiest thing to underestimate; cap
max_tokensand measure real completions. - Multi-turn growth — chat history accumulates; summarize or truncate or your per-turn input grows every turn.
Common estimation mistakes
- Forgetting input is most of RAG — retrieved context, not the answer, is the cost.
- Pricing all traffic at the flagship rate — route by difficulty and estimate the blend.
- Ignoring retries — failures and re-asks add real tokens; budget a margin.
- Treating input = output price — they differ 2-8x; use both numbers.
Compare the same estimate across 300+ models
DataLLM Lab shows live per-model pricing and lets you run the same workload across providers — so your estimate becomes a one-click comparison.
FAQ
How do I estimate LLM API costs?
cost = input_tokens × input_price + output_tokens × output_price (per million). Estimate tokens/request, multiply by monthly volume, apply the rates. ~4 chars ≈ 1 token.
How are tokens counted?
Sub-word chunks (~4 chars or ~0.75 words each in English), varying by language and content. Both input (prompt + context) and output are billed, at different rates.
What is the cost formula?
cost = input_tokens/1M × input_price + output_tokens/1M × output_price. Output is usually 2-8x pricier, so output-heavy workloads cost more than input counts suggest.
Why is output more expensive?
Generating tokens needs a full forward pass each; input is processed in parallel. So output is priced 2-8x higher than input.
How do I estimate tokens before building?
~4 chars/token, or run a real tokenizer on samples. Estimate a typical request's input + output, multiply by monthly requests, add a margin for retries.
What makes estimates wrong?
Forgetting context counts as input, underestimating output, ignoring retries/history growth, and pricing all traffic at the flagship rate. Estimate per workload.
Is there a cost calculator?
Build one with the formula, or use a gateway with live per-model pricing to compare the same workload across providers instantly.
How much does a chatbot cost per month?
By volume and model — a modeled support chatbot is ~$500/mo on Claude Opus, $280 on GPT-5.4, or $13 on DeepSeek V3.2. Model choice swings it 30-40x.
DataLLM Lab