How do I estimate LLM costs?
Multiply the number of requests by the tokens per request and the price per token, and do it separately for fresh input, cached input and output, because each has its own price. Then add retries, agent loops and growth, and check the estimate against real logs as soon as you have them.
Last updated
Step by step
- 1List each AI feature and how often it runs: per user per day, per document, per ticket.
- 2Measure or estimate tokens per call for the system prompt, context, user input and output. A token counter on real examples beats a guess.
- 3Split input into the part that repeats (cacheable with prompt caching) and the part that changes.
- 4Count calls per task: an AI agent or a RAG pipeline may make several model and embedding calls per user request.
- 5Apply each model's current input, cached input and output prices from the provider's price page.
- 6Add a margin for retries, errors and longer-than-average inputs, then multiply by expected volume.
Check it against reality
Estimates are often wrong because conversations get longer, agents take more steps than planned and outputs run long. Log token counts and cost per feature from the first prototype, and recheck the estimate with real traffic.
Cost depends on the token mix, not only the total: an output-heavy feature and an input-heavy one with the same total can cost very different amounts.
Check it for your case.
Common follow-up questions.
Where do I find current prices?
On each provider's own pricing page. Our LLM API pricing page lists them side by side with a source and date for each.
Should I estimate per user or per task?
Per task first, then multiply by tasks per user. It shows which features drive cost and where to optimise.
How do I stop costs running away?
Set limits: maximum output length, maximum agent steps, per-user quotas and spending alerts at the provider.
Related questions and guides.
- How do I reduce LLM API costs?Question
- Does prompt caching save money?Question
- How much does an AI agent cost?Question
- AI agent vs workflow automationComparison
- RAG vs fine-tuningComparison
- GlossaryEvery term, in plain words.
- LLM API pricingModel prices side by side, with sources.
- Pricing librarySoftware and API prices, each with its source and date.
- AI automationHow OceanLab automates company workflows with AI.