How to Estimate LLM API Costs Before You Build
The good news about language model APIs is that pricing is simple on paper: you pay per token. The trap is that “per token” hides a few multipliers that decide whether a feature costs $50 a month or $5,000.
Here is how to get a defensible number before you commit.
The basic formula
Text is split into tokens — chunks of roughly three to four characters. You pay for two things:
- Input tokens: your prompt, including the system instructions and any context you attach.
- Output tokens: what the model generates back.
Both are usually priced per million tokens, and output is typically three to five times the input rate because generating text is more work than reading it.
cost per request = (input tokens ÷ 1,000,000 × input price)
+ (output tokens ÷ 1,000,000 × output price)
Multiply by how many requests you expect, and you have a monthly figure.
A rough sizing guide while you are sketching: 1,000 tokens ≈ 750 words ≈ 4,000 characters of English. Code and other languages run higher.
What a naive estimate misses
The formula above assumes one clean request per call. Production is messier:
- Retries and failures. Timeouts, rate limits, malformed responses — each retry is another paid request.
- Tool-calling round trips. An agent that calls three tools before answering is four full requests, each resending the growing conversation.
- Thinking tokens. Extended reasoning is billed as output, and it can be several times the length of the visible answer.
- Images and audio in the input, which are converted to tokens at their own rates.
Many teams budget 20% to 50% above the naive number to absorb this.
The levers that move the bill
In rough order of impact:
- Model choice. Use a small, cheap model for the easy calls — classification, routing, short extractions — and a larger one only where quality visibly depends on it. This is often a 10x difference.
- Output length. Cap the maximum response. A prompt that returns a 2,000-token essay when 200 words would do is overpaying on the expensive half of the bill.
- Prompt caching. If every request resends the same large system prompt or document, most providers can cache it and re-read it at around 10% of the input price. For chat and agent apps this is a big saving on the input side. Discounts and any one-off write cost vary by provider.
- Trim the prompt. A long, unchanging preamble is cheap once and expensive across a million calls. Shorter instructions, and only the context the task needs.
- Batch what is not urgent. Many providers run non-real-time work asynchronously at around half price.
Work an example
Say a support-triage feature: 1,500 input tokens and 500 output tokens per request, 100,000 requests a month, on a mid-tier model at $2 / $10 per million tokens.
- Input: 1,500 × 100,000 = 150M tokens × $2 = $300
- Output: 500 × 100,000 = 50M tokens × $10 = $500
- About $800 a month before retries and margin.
Now add 40% caching on the input (a fixed system prompt), and the input side drops toward $190 — a $110 saving for one config change.
Size yours
The LLM API cost calculator takes the per-million-token prices, your request volume and average tokens in and out, and returns cost per request, per 1,000 requests, per day, per month and per year, with the input and output halves broken out. It has a caching slider so you can see that lever directly. Copy the current prices from your provider’s pricing page — LLM pricing changes often, so the presets are a reference point, not a quote.