How to cut LLM costs: caching, batching, routing and smaller models

One $20,000 monthly model bill, cut step by step to $4,809 with limits, caching, batching and routing aimed at the lines that drive it.

Brandon Holt
Updated
November 27, 2026
18
min read
Summarize
Key takeaways
  • In the example, 20 customers (5% of the base) drive 46% of a $20,000 monthly model bill, so measure cost per customer and per feature before you cut anything.
  • Prompt caching alone saves $6,019 a month, 31% of the bill, with no change to answers; on Claude Sonnet 5.5 a cache read costs $0.10 per million tokens against $2 for fresh input.
  • Per-customer limits, caching, the Batch API, routing and shorter prompts take the bill to $4,809, a 76% cut, while the enterprise agent stays on Opus 5.5.

To cut LLM costs without hurting the customers who matter, measure cost per customer and per feature first. Then fix the biggest lines in this order: runaway usage, prompt caching, the Batch API, model routing, shorter prompts and response caching. In this guide's example, those steps take a $20,000 monthly model bill to $4,809, and the agent the largest customers pay for stays on Opus 5.5.

Prices checked on November 27, 2026, from Anthropic's pricing page and OpenAI's pricing page.

Where an LLM bill comes from: four kinds of tokens

A model call bills up to four kinds of tokens. Input tokens are everything you send: the system prompt, tool definitions, retrieved documents and chat history. Output tokens are what the model writes, and on current Claude and OpenAI flagship models they cost five times as much as input.

Cached tokens are input the provider processed on a recent call and stored, and a cache read costs a small fraction of the input rate. Reasoning tokens are the model thinking before it answers. Anthropic bills thinking as output tokens, even when the response leaves the thinking text out, so a model that thinks at length raises your output count without writing a longer answer.

ModelInputCache readOutputBatch inputBatch output
Claude Opus 5.5$4.00$0.20$20.00$2.00$10.00
Claude Sonnet 5.5$2.00$0.10$10.00$1.00$5.00
Claude Haiku 5.5$0.10$0.01$0.50$0.05$0.25
GPT-6.2 Astra$8.00$0.40$40.00$4.00$20.00
GPT-6.2 Sol$2.00$0.10$10.00$1.00$5.00
GPT-6 Luna$0.10$0.01$0.50$0.05$0.25

Source: Anthropic and OpenAI pricing pages, USD per million tokens, standard tier. Haiku 5.5 prices apply to prompts up to 100,000 tokens and GPT prices to prompts up to 272,000 tokens.

The price of a call moves with four levers: the model's rate, the share of input that hits the cache, whether the call can wait for batch prices, and how many tokens go in and come out. AI cost optimization comes down to pulling the right lever on each line of the bill. For every model's rates, see our breakdown of Claude API cost per token and our breakdown of OpenAI API cost.

One trap when you compare models: Anthropic says Claude 4.7 and later models use a tokenizer that produces about 30% more tokens for the same text. Compare models on cost per task, measured on your own traffic.

The example used in this guide

Example data. The product is an AI support assistant sold to 400 B2B software companies, and it runs on Claude. It spends $20,000 a month on model calls across four features.

FeatureModelCalls a monthCost per callMonthly cost
Chat repliesSonnet 5.5400,000$0.025$10,000
Auto-resolve agentOpus 5.550,000 steps$0.080$4,000
Ticket summariesSonnet 5.5275,000$0.012$3,300
Ticket taggingSonnet 5.5600,000$0.0045$2,700
Total$20,000

Example data. A chat reply sends 10,000 input tokens and gets 500 back. An agent step averages 16,000 in and 800 out, a summary 4,000 in and 400 out, and a tag 2,000 in and 50 out.

chat reply = 10,000 × $2 ÷ 1M  +  500 × $10 ÷ 1M
           = $0.020 + $0.005
           = $0.025

Of the 10,000 input tokens in a chat reply, 6,000 repeat on each call for a given customer: the system prompt, the tool definitions and that customer's product docs. The other 4,000 are retrieved help articles (3,000) and conversation history (1,000). An auto-resolve task runs 10 steps, and each step resends the growing transcript. Each lever in this guide works on one of those parts.

Find which customers and features drive the bill

A cut applied evenly lands hardest on the customers who pay you the most. Say you move every call to a cheaper model to save 30%. The example saves about $6,000, and Halden Bank, which pays $6,000 a month mostly for the auto-resolve agent, gets a weaker agent. LLM cost optimization starts the other way around: measure first, then cut where the money goes.

To measure, tag each model call with the customer and the feature that made it. Store the token counts from each response's usage object and price them with a dated price table, so old calls keep the price they ran at. Your provider's bill knows your models and API keys. Only your code knows which customer made each call.

Customers by AI costCountAI costShare of bill
Top 5%20$9,20046%
Next 20%80$6,00030%
Other 75%300$4,80024%
All400$20,000100%

Example data. Customers ranked by monthly model cost.

46%
of the bill comes from 20 customers, 5% of the base.

The top 20 split into two kinds of customer. Some cost a lot because they use the product hard and pay for it. Others cost a lot because something is wrong. The top five show both:

CustomerPlanPays a monthAI costMain driver
Halden BankEnterprise$6,000$1,240Agent on Opus 5.5
FernwayStarter$99$930Chat loop, 36,000 calls in 3 days
Corvid HealthEnterprise$5,000$880Chat with a large uncached prefix
Marlowe FreightGrowth$499$610Tagging 90,000 tickets
TesselEnterprise$4,000$560Agent on Opus 5.5

Example data. The five most expensive customers in one month.

Halden Bank and Tessel pay $10,000 between them against $1,800 of AI cost. They are the healthiest accounts on the list, and their agent should stay as it is. Fernway pays $99 and costs $930. Corvid Health and Marlowe Freight are profitable, but each is paying full price for tokens the product resends or could process later.

Put the two views side by side and four lines stand out:

  • A runaway loop: Fernway's 36,000 extra chat calls, $900.
  • Uncached prefixes: 6,000 identical tokens on each chat call, and a growing transcript resent on each agent step.
  • Work at live prices that nobody reads for hours: summaries and tagging, $6,000.
  • Easy work on a mid-size model: tagging and simple chat questions that a smaller model can answer.

This skew is common in AI products, and our timeline of Cursor's pricing model shows what happens when a few power users decide a plan's margin. For margin per customer and per plan, see our guide to AI unit economics.

Lancelot's SDK tags each call with the customer and feature and stores token counts, never prompts. Margin intelligence then ranks the customers and features driving cost and flags large prompts sent without caching, which is where the next chapters start.

Stop runaway loops and abuse with per-customer limits

Fix the leaks before you tune anything. Fernway's loop costs $900 this month and will cost the same next month, and prompt caching would only make each wasted call cheaper.

Fernway's help desk integration kept retrying a failed webhook, and each retry sent the same ticket to chat again: 36,000 calls in 3 days, about 8 a minute. The same pattern shows up as abuse when someone scripts a free account against your API. OWASP files both under LLM10:2025 Unbounded Consumption, names the cost side "Denial of Wallet", and lists rate limiting, throttling and anomaly detection among the defenses. Our explainer on denial of wallet covers the attack side.

Limits to enforce inside your app

Your provider sees one account. Only your code can tell one customer from another, so the limits belong there:

  • A rate limit per customer and feature, in calls a minute.
  • A daily dollar budget per plan. A $5 daily budget on Starter would have held Fernway's loop to about $15.
  • A step cap on agent tasks, such as 25 steps, so one task can't run all night.
  • max_tokens on each call. Anthropic's docs describe effort as soft guidance and max_tokens as a strict limit.
  • Friction on free trials, such as a verified work email before the agent turns on.

Decide in advance what happens when the limit check itself fails. Failing open keeps paying customers working, and failing closed protects the bill. Most B2B products should fail open for paid plans and closed for free trials.

A heavy customer who is using the product as designed needs a price, and our guide to AI pricing models covers hybrid plans with metered overage. Fernway needs a fix to its webhook.

Lancelot flags a runaway loop when one customer makes more than 50 calls in 10 minutes on the same feature and model with prompt sizes within 10%, which Fernway's 8 calls a minute trip. For faster spikes, its SDK has an emergency stop at 600 calls a minute or $50 in 5 minutes per customer, with a 5-minute cooldown, and it fails open (Runtime protection).

bill after the loop fix = $20,000 − $900
                        = $19,100

Prompt caching: pay less for the prefix you resend

Prompt caching stores the processed start of your prompt so the next call that begins with the same tokens reads it at a discount. On Anthropic, a 5-minute cache write costs 1.25 times the input price and pays for itself after one read. A 1-hour write costs 2 times and pays off after two reads. Cache reads on Sonnet 5.5 and Opus 5.5 cost 0.05 times input: $0.10 and $0.20 per million tokens.

Three rules from Anthropic's prompt caching docs decide whether you get those prices:

  • Order matters. The cache builds in the order tools, system, messages, and a change at one level invalidates it and everything after. Editing a tool definition clears the whole cache.
  • Short prompts don't cache. The minimum is 512 tokens on current Claude models, and a shorter prompt runs uncached with no error.
  • Check the usage fields. If cache_creation_input_tokens and cache_read_input_tokens are both 0, the call wasn't cached.

OpenAI caches prompts by default on supported models. On GPT-5.6 and later the minimum is 1,024 tokens, and a write costs 1.25 times input for the default 30-minute lifetime. OpenAI also advises putting stable instructions and shared reference material first. On both providers, keep timestamps, user names and retrieved text out of the prefix, because one changed token near the top turns the rest into a cache miss.

Caching the example's chat and agent

Example data. Chat puts the system prompt, tools and the customer's docs (6,000 tokens) first and gets an 85% cache hit rate. The agent caches its transcript as it grows, so each step reads 14,400 tokens from cache and writes 1,600 new ones.

chat reply, cached
  prefix   6,000 × (0.85 × $0.10 + 0.15 × $2.50) ÷ 1M = $0.00276
  rest     4,000 × $2 ÷ 1M                            = $0.00800
  output     500 × $10 ÷ 1M                           = $0.00500
  total                                               = $0.01576  (was $0.025)

364,000 calls:  $9,100 → $5,737   saves $3,363

agent step, cached
  reads   14,400 × $0.20 ÷ 1M  = $0.00288
  writes   1,600 × $5 ÷ 1M     = $0.00800
  output     800 × $20 ÷ 1M    = $0.01600
  total                        = $0.02688  (was $0.080)

50,000 steps:   $4,000 → $1,344   saves $2,656
$6,019
saved a month by caching, with no change to any answer. The bill drops to $13,081.

Hit rate depends on traffic. Corvid Health asks a question every few seconds and keeps its cache warm. A small customer that asks once every 20 minutes misses the 5-minute cache each time, and the 1-hour cache suits it better. Our breakdown of Claude prompt caching works through the break-even for each lifetime.

Batch APIs: half price for work that can wait a day

A batch API takes a file of requests, runs them when capacity allows and charges half price. Anthropic's Message Batches API takes up to 100,000 requests or 256 MB per batch, finishes most batches within an hour, and expires anything left after 24 hours without billing it. OpenAI's Batch API takes up to 50,000 requests or 200 MB, completes within 24 hours, and keeps batch jobs out of your standard rate limits.

OpenAI also discounts background requests on GPT-6.2 Astra, GPT-6.2 Sol, GPT-6.1 Terra and GPT-6 Luna: 30% off for a 2-hour window and 40% off for an 8-hour window. Those windows suit work that should land the same morning.

Batch fits any work nobody reads in the next few minutes: tagging, summaries for reports, evals, backfills and nightly digests. Chat and agent steps a person is waiting on stay on the live API. Caching discounts stack with batch, but Anthropic provides cache hits in batches on a best-effort basis, says users typically see hit rates from 30% to 98%, and suggests the 1-hour cache for batches with shared context.

Example data. The summaries feed a weekly report and the search index, and tagging runs overnight, so both move to Message Batches.

summaries  275,000 × (4,000 × $1 + 400 × $5) ÷ 1M  = $1,650  (was $3,300)
tagging    600,000 × (2,000 × $1 +  50 × $5) ÷ 1M  = $1,350  (was $2,700)

saves $3,000   bill $13,081 → $10,081

Build it as a queue. Write each request to a table when it happens, submit a batch every hour, and write results back by custom_id. Your product then shows a summary within the hour on most days, at half the price.

Model routing: send easy calls to smaller models

Model routing picks a model for each request. Haiku 5.5 costs $0.10 per million input tokens and $0.50 per million output, and Sonnet 5.5 costs $2 and $10, a 20 times gap. OpenAI's GPT-6 Luna and GPT-6.2 Sol sit 20 times apart too. Long prompts narrow it: Haiku 5.5 charges $0.50 and $2.50 once a prompt passes 100,000 tokens.

An LLM router takes one of three shapes:

  • Rules per feature. Tagging always goes to the small model. Rules add no extra model call and no latency.
  • A classifier. A cheap model or a heuristic labels each request easy or hard first.
  • A cascade. The small model answers first, a check scores the answer, and failures retry on the larger model. You pay for both calls on the retries.

Route with evals. Pull a few hundred real requests per feature with answers you know are good, run them on the smaller model, and route only the features where it passes. Our comparison of Claude Haiku vs Sonnet shows where the cascade stops paying, which is when nearly every call escalates.

Route by customer as well as by feature. Halden Bank and Tessel pay for the agent on Opus 5.5, and it earns its cost there. A Starter customer losing you money is a better place to try a cheaper model first. Lancelot's agent can switch one customer to a cheaper model you've approved in advance, starting as a suggestion you accept or undo (the Agent).

Routing the example

Example data. Tagging moves to Haiku 5.5 in the batch queue. In chat, 60% of questions are simple (password resets, how-to steps) and go to Haiku first, and 15% of those fail a check and retry on Sonnet. The agent stays on Opus 5.5.

tagging on Haiku batch
  600,000 × (2,000 × $0.05 + 50 × $0.25) ÷ 1M  = $67.50   (was $1,350)

chat, cached Haiku reply                        = $0.0008135
  simple questions  218,400 × $0.0008135       = $177.67
  retries on Sonnet  32,760 × $0.01576         = $516.30
  total                                        = $693.97  (was $3,441.98)

saves $4,031   bill $10,081 → $6,050

Routing on its own would have saved $6,933 against the $19,100 bill. After caching and batching it saves $4,031, because each lever works on what the previous ones left.

How to reduce token costs: shorter prompts and outputs

Token optimization is how you reduce token usage: send fewer tokens and ask for fewer back. Trimming pays most on the part of the prompt that changes on each call, because once the prefix is cached, 1,000 cached tokens on Sonnet 5.5 cost $0.0001. Spend your effort on retrieved context, history and output.

Retrieve fewer, better chunks

RAG pipelines tend to send more context than the model uses. The example retrieves six 500-token help articles per question. A reranker that keeps the best three cuts 3,000 tokens to 1,500, and smaller chunks with their heading attached can answer better than whole pages.

Summarize old chat history

Keep the last few turns word for word and replace older turns with a short running summary. In the example, history drops from 1,000 tokens to 600. On long conversations the saving grows with each turn, since the full history resends on every call.

Cap output and reasoning

Output costs five times input, so shorter answers save the most per token. Ask for the length you want in the prompt and set max_tokens as a hard ceiling. For thinking models, Anthropic advises lowering effort first to cut cost, since effort scales the whole response down, thinking included. The example cuts chat replies from 500 tokens to 350.

Prompt compression

Prompt compression tools rewrite long context into fewer tokens by dropping words the model doesn't need. Compress the dynamic part of the prompt only, since a compressed prefix breaks your cache, and test the output against your evals before you ship it.

Watch the long-context price tiers

Some prices step up with prompt length. Haiku 5.5 charges five times more on prompts over 100,000 tokens, and GPT-6.2 Sol charges $4 per million input tokens and $15 output above 272,000. Trimming a prompt under the line can cut its price by more than the tokens removed.

Sonnet chat reply after trimming
  prefix   6,000 cached           = $0.00276
  dynamic  2,100 × $2 ÷ 1M        = $0.00420
  output     350 × $10 ÷ 1M       = $0.00350
  total                           = $0.01046  (was $0.01576)

Sonnet replies  178,360 × $0.00530 saved  = $945
Haiku replies   218,400 × $0.000265 saved = $58

saves $1,003   bill $6,050 → $5,047

Example data. Sonnet replies include the 32,760 retries from routing.

Semantic caching: skip the call for repeat questions

Prompt caching makes the input cheaper. A response cache skips the model call. An exact-match cache returns a stored answer when the normalized prompt matches one it has seen. Semantic caching embeds the question and returns a stored answer when a past question scores above a similarity threshold. Both count as LLM caching, along with the provider's prompt cache.

Response caches carry four risks of their own:

  • Near misses. "How do I cancel my plan" and "how do I cancel my order" sit close together and need different answers. Set the threshold high and test it on real traffic.
  • Stale answers. Expire entries when the customer's docs change.
  • Leaks between customers. Scope the cache key to one customer, so Corvid Health never sees an answer written from Halden Bank's docs.
  • Personal answers. Anything that depends on the user's account can't come from a cache.

Example data. With the cache scoped per customer, 12% of chat questions match a stored answer.

chat after trimming  = $1,985
12% served from cache = $1,985 × 0.12 = $238

saves $238   bill $5,047 → $4,809

Example data. Leaves out the cost of the embedding lookup and storage.

Semantic caching saves the least here because the earlier steps already cut chat to $1,985. It pays off sooner in public-facing products where thousands of people ask the same question. In most B2B products it belongs last.

The order to cut LLM costs in, with the savings

The strip below applies four levers, each on its own, to the $19,100 bill after the loop fix, with the effort each took a small team in the example.

Prompt caching
−$6,019
31% of the bill, 2 days
No change to answers
Batch API
−$3,000
16% of the bill, 3 days
Results within 24 hours
Model routing
−$6,933
36% of the bill, 3 weeks
Needs evals to hold quality
Token trimming
−$1,929
10% of the bill, 1 week
Needs evals to hold quality

Example data. Each lever on its own against $19,100. Effort is an estimate.

Prompt caching wins on savings per day of work, and it leaves every answer the same. Routing saves the most on its own, but it takes evals and a few weeks, and a bad route reaches customers. Run caching first, batch next, and route once the evals exist.

The savings shrink as you stack them, because each lever cuts the base for the next one. Applied in order, the example lands here:

StepSavedBill after
Starting bill$20,000
1. Fix the loop, add per-customer limits$900$19,100
2. Prompt caching on chat and agent$6,019$13,081
3. Batch API for summaries and tagging$3,000$10,081
4. Route tagging and simple chat to Haiku 5.5$4,031$6,050
5. Trim context, history and output$1,003$5,047
6. Semantic caching per customer$238$4,809
Total$15,191$4,809

Example data. The same product, one step at a time.

$4,809
a month, down 76% from $20,000. Halden Bank's agent still runs on Opus 5.5.

The new bill has a new shape. Summaries are now the second-largest line at $1,650, after chat at $1,747, and they are the next feature to test on Haiku. Measure cost per customer and per feature again each month, and keep the per-customer limits from chapter 3 switched on while you change models and prompts, since a new prompt is a common place for a loop to start.

Questions about cutting LLM costs

How do I reduce LLM API costs?

Measure cost per customer and per feature first, then fix the biggest lines: stop runaway usage, cache repeated prompt prefixes, move work that can wait to the Batch API, route easy calls to smaller models and trim prompts. In this guide's example, those steps cut a $20,000 monthly bill to $4,809.

How do I reduce token costs?

Send fewer tokens and pay less for the ones you send. Cache the static prefix, retrieve fewer and smaller chunks, summarize old chat history, cap output with max_tokens and lower reasoning effort. Output costs five times input on current Claude and OpenAI flagship models, so shorter answers save the most per token.

How much does prompt caching save?

On Claude Sonnet 5.5 and Opus 5.5, a cache read costs 0.05 times the input price, and a 5-minute cache write pays for itself after one read. In this guide's example, caching cut chat and agent costs by $6,019 a month, 31% of the bill, with no change to any answer.

When should I use the Batch API?

Use it for work nobody reads within a few minutes: tagging, report summaries, evals and backfills. Anthropic and OpenAI both charge 50% less for batch requests and return results within 24 hours, and Anthropic says most batches finish within an hour.

What is an LLM router?

An LLM router picks a model for each request, sending easy work to a small, cheap model and hard work to a larger one. It can use fixed rules per feature, a classifier, or a cascade that tries the small model first and retries on the larger one when a check fails.

Is semantic caching worth it?

Semantic caching pays off when many people ask the same questions and the answers rarely change. In most B2B products it saves less than prompt caching or routing and adds risk, since a similar question can get the wrong stored answer. Scope the cache per customer and expire entries when your docs change.

Will a smaller model hurt answer quality?

It can, so route by feature and test on real traffic before you switch. Classification and tagging tend to hold up on small models. Keep your largest customers' most valuable features on the stronger model until an eval shows the smaller one passes.

How do I stop one customer from running up my AI bill?

Enforce limits per customer inside your app: calls a minute, a daily dollar budget per plan, a step cap on agent tasks and max_tokens on each call. Your provider sees one account, so only your code can tell one customer from another.

Brandon Holt
Founder
In Lancelot

Put a limit on your worst night of AI spend.

Runtime protection enforces per-customer limits and budgets inside your app, and catches runaway loops and abuse.

Lancelot runtime protection settings with per-customer limits

Keep reading

All guides →
Running AI in production
/
18
min read

How to cut LLM costs: caching, batching, routing and smaller models

One $20,000 monthly model bill, cut step by step to $4,809 with limits, caching, batching and routing aimed at the lines that drive it.

10
chapters
Updated
November 27, 2026
AI unit economics
/
18
min read

AI unit economics: gross margin, COGS and cost per customer

One AI product with 200 customers, worked from formulas to board slide: the blended margin, the 19 customers losing money, and four fixes.

10
chapters
Updated
November 27, 2026
Pricing AI products
/
20
min read

How to price AI features: flat, usage, credits or hybrid

One AI product with 100 customers, priced four ways, plus seats, outcomes, free tiers and how to change prices without losing trust.

10
chapters
Updated
November 27, 2026

Get the numbers when they change.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
New guides, dispatches and model price changes. Unsubscribe anytime.