AI
How to estimate and cut your LLM API costs
How to estimate and cut LLM API costs: token pricing, a worked monthly estimate, and a table of savings from caching, routing, batching and trimming.
By Bilal Khursheed, Founder & CEOUpdated 8 min read

LLM API cost is roughly requests × tokens per request × price per token, and on current flagship models output tokens cost 5x as much as input. The largest documented savings come from prompt caching (cached input up to 95% off on OpenAI, 0.1x the input price on most Claude models) and batch processing (50% off). After that: route easy requests to cheaper models, cap output and trim retrieved context.
You rarely need to optimize until you are at volume, but you should measure from day one so you know where the money goes.
How token pricing works
- A token is a chunk of text, usually part of a word. How many tokens the same text produces depends on the tokenizer: Anthropic notes that its newer tokenizer (Claude 4.7 and later) produces about 30% more tokens for the same text than earlier models. Count tokens with the provider's own tools rather than estimating from word counts.
- You pay for input tokens (your prompt plus any context you attach) and output tokens (the model's response).
- Providers price per million tokens, and output is more expensive than input: 5x on every current Claude and OpenAI flagship model at standard short-prompt rates, at the time of writing (November 2026).
- Long context inflates cost fast. Big system prompts and lots of retrieved RAG chunks are billed as input on every call, and some models charge higher rates past a threshold: OpenAI's pricing page lists higher rates for prompts over 272K tokens, and Anthropic charges more on Claude Haiku 5.5 for prompts over 100,000 tokens.
Estimating your monthly cost
Before optimizing, get a rough number. Here is the formula with Claude Sonnet 5.5 list prices at the time of writing (November 2026), $2 per million input tokens and $10 per million output; GPT-6.1 Sol lists at the same rates.
A back-of-the-envelope monthly LLM cost estimate.
// List prices per 1M tokens (Claude Sonnet 5.5, November 2026).
// Always check your provider's current pricing page.
const inputPrice = 2.0;
const outputPrice = 10.0;
const requestsPerMonth = 100_000;
const avgInputTokens = 1_200; // prompt + retrieved context
const avgOutputTokens = 400;
const inputCost = (requestsPerMonth * avgInputTokens / 1_000_000) * inputPrice; // 240
const outputCost = (requestsPerMonth * avgOutputTokens / 1_000_000) * outputPrice; // 400
const monthlyCost = inputCost + outputCost; // 640 USD
Output is a quarter of the tokens but over 60% of the bill, which is why output limits matter as much as context size.
Which techniques cut LLM costs, and by how much?
| Technique | What it does | Typical impact | Trade-off |
|---|---|---|---|
| Prompt caching | Reuses a repeated prompt prefix (instructions, examples, documents) | Cached input up to 95% off on OpenAI; 0.1x base input on most Claude models, 0.05x on Opus 5.5 and Sonnet 5.5 | Only the identical prefix is cheaper; Claude charges extra to write the cache |
| Model routing | Sends easy requests to a cheaper model | Claude Haiku 5.5 input is 40x cheaper than Opus 5.5; GPT-6 Luna is 20x cheaper than GPT-6.1 Sol | Needs an evaluation set per route |
| Batching | Runs non-urgent requests asynchronously | 50% off input and output on both providers | Results within hours, not seconds |
| Output limits | Caps and shortens responses | Each output token cut saves 5x what an input token does | Truncated answers if the cap is too tight |
| Retrieval trimming | Sends fewer, tighter chunks | Proportional to input tokens removed; no vendor benchmark, so measure | Lower recall if you cut too far |
| Semantic caching | Reuses stored answers for near-identical questions | A hit skips the model call entirely; savings track your hit rate | Stale or wrong answers if matching is too loose |
Figures are from Anthropic's pricing page, OpenAI's pricing page and OpenAI's Batch API guide, at the time of writing (November 2026).
Prompt caching: the underrated win
Most production prompts repeat the same long prefix on every call: system instructions, tool definitions, few-shot examples, sometimes a whole policy document. Caching bills that prefix at a steep discount.
How to structure for it: put the large static part first and the small dynamic part (the user's question, timestamps, user details) last. OpenAI's caching guide is explicit that the entire rendered prefix must match, so a timestamp near the top of the prompt defeats the cache on every call.
How the two providers differ:
- OpenAI caches automatically on supported models, with no code change, for prompts of at least 1,024 tokens on GPT-5.6 and later.
- Anthropic caches when you add a
cache_controlfield. Writing to the cache costs 1.25x the base input price for a 5-minute cache or 2x for a 1-hour cache, so caching pays off after one read with the 5-minute cache and after two with the 1-hour cache.
Run the numbers on the estimate above. If 1,000 of the 1,200 input tokens are a shared prefix served from cache on Claude Sonnet 5.5 (a cache hit costs $0.10 per million tokens), monthly input drops from about $240 to about $50, before the occasional cache write. Output is unchanged, which is why caching and output limits work best together.
Model routing: pay for capability only where it is needed
Most products have a mix of easy and hard requests. Classifying a ticket, extracting a date or answering a common question does not need the top tier. Three routing patterns, in order of effort:
- Rule-based: route by feature. Tagging and extraction go to a small model; drafting and multi-step reasoning go to a larger one.
- Cascade: try the cheap model first and escalate when its answer fails a check (schema validation, a confidence score, an empty result).
- Classifier: a small model labels each request's difficulty and picks the tier.
Whatever the pattern, keep an evaluation set per route so a cheaper model is proven, not assumed. Our comparison of OpenAI and Anthropic Claude lists the current tiers, and evaluating RAG systems covers building the test set.
Batching, output limits and trimming
- Batch anything a user is not waiting for. OpenAI says each batch completes within 24 hours and names evaluations, dataset classification and embedding content as typical uses. Nightly summaries, back-filling tags and re-scoring old records fit too.
- Cap output. Set a maximum output length per feature, ask for a structured format instead of prose where the result feeds code, and tell the model not to restate the question.
- Trim retrieved context. Sending ten chunks "to be safe" multiplies input cost. Re-rank and send the best few, then confirm on your test set that answer quality holds. Our RAG pipeline guide covers re-ranking.
Semantic caching: skip the call entirely
A semantic cache stores previous answers keyed by an embedding of the question and returns one when a new question is close enough. For support bots with many repeated questions, a hit costs a lookup instead of a model call. Three rules keep it safe:
- Scope the cache key to the tenant and the user's permissions, so one customer never sees an answer built from another's data. The same isolation rules apply as in multi-tenant SaaS architecture.
- Expire entries when the source documents change.
- Set the similarity threshold conservatively, and check hits against your evaluation set before widening it.
Don't optimize prematurely
The most expensive mistake is optimizing before you measure. Log input, output and cached tokens and the model for every request, tagged by feature, then fix the one or two features that dominate the bill. A dashboard of token spend by feature is worth more than a dozen micro-optimizations.
How we keep AI features affordable
We measure token spend per feature, route each request to the cheapest model that clears the quality bar, structure prompts for caching, and keep context tight. It is the same approach we cost into AI chatbot builds. If your bill is growing faster than usage, our engagement models include short, fixed-scope reviews.
Frequently asked questions
How much do LLM APIs cost?
They are priced per million tokens, separately for input and output, and rates vary widely by tier. At the time of writing (November 2026), list prices run from $0.10 per million input tokens on the smallest models to $10 on the largest, with output at 5x input. Your bill is roughly requests × tokens per request × price, so it scales with traffic and with how much context you send.
What is a token?
A token is a chunk of text, usually part of a word. You pay for the tokens in your prompt and context (input) plus the tokens in the model's response (output). The number of tokens in the same text varies by tokenizer, so measure with your provider's token counter.
How do I estimate my monthly AI bill?
Multiply expected monthly requests by average input tokens, divide by a million and multiply by the input price; do the same for output, then add the two. For 100,000 requests a month at 1,200 input and 400 output tokens, at $2 and $10 per million, that is about $640.
What's the single biggest cost lever?
Model choice, closely followed by prompt caching. Price gaps between tiers are large: at the time of writing (November 2026), Claude Haiku 5.5 input costs a fortieth of Claude Opus 5.5, so routing easy requests to a small model cuts cost sharply. Measure quality on each route before you switch.
Does using a cheaper model hurt quality?
Not if you route by difficulty and measure against an evaluation set. Many requests are easy and a cheaper model handles them well; a cascade that escalates failed answers to a larger model protects the hard cases. You only pay for the top tier where it earns its keep.
What is prompt caching?
It's a provider feature that reuses a repeated prompt prefix, such as your instructions and examples, and bills it at a discount on later calls: up to 95% off on OpenAI, and 0.1x the input price on most Claude models. OpenAI applies it automatically; Anthropic needs a cache setting and charges a premium to write the cache. Put static content first and dynamic input last.





