All posts

How to reduce LLM API costs: caching, batching and routing, in the order they pay off

How to reduce LLM API costs without degrading quality: prompt caching, batch processing and model routing, what each one actually saves, and the prompt-design mistakes that silently turn the savings off.

CodeKryptUpdated 10th Nov 2026 8 min read

If you want to reduce LLM API costs, the instinct is to switch to a cheaper model. That is usually the last lever worth pulling, not the first. The cheaper wins sit in how requests are shaped: whether the repeated part of your prompt is cached, whether work that does not need an instant answer is batched, and whether every request really needs your most expensive model.

This post goes through those three levers in the order they tend to pay off, with the mechanics from the providers' own documentation, and the mistakes that quietly switch the savings off.

Which lever saves the most?

LeverWhat it changesNeeds a quality trade-off?Effort
Prompt cachingPrice of the repeated prefixNoLow: reorder the prompt
Batch processingPrice of non-urgent workNo, but you waitLow to medium
Model routingWhich model handles which taskYes, measure itMedium to high
Shorter outputs and contextTokens per requestSometimesOngoing

The first two reduce price without touching answer quality. Routing and trimming do, which is why they come with an evaluation requirement (more on that below).

How does prompt caching reduce LLM API costs?

Most production prompts are mostly the same every time: a long system prompt, tool definitions, a policy document, a few examples. Prompt caching lets the provider reuse the work it already did on that identical prefix and bill the reused part at a discount.

Anthropic's prompt caching documentation sets out the pricing structure:

OpenAI's prompt caching guide describes a similar shape for its newer models: caching triggers automatically on identical prompt prefixes, reads cost 0.1× the normal rate on most models, writes cost 1.25×, and a cached prefix stays eligible for 30 minutes after its most recent use. Older models have different options, so check the guide for the model you actually use.

What does that look like in numbers?

An illustration, using the Claude Opus 5.5 figures from Anthropic's docs ($4 per million base input tokens, $5 for a 5-minute cache write, $0.20 for a cache read). Assume a 10,000-token stable prefix reused across 1,000 requests inside the cache lifetime. Counting only that prefix, not the user's question or the output:

ApproachPrefix cost for 1,000 requests
No caching10M tokens × $4/M = $40.00
With caching1 write ($0.05) + 999 reads ($2.00) = about $2.05

This is arithmetic on published list prices, not a measured result from any system, and real savings depend on your hit rate, your traffic gaps and the share of each request that is stable. But it shows why the prefix is where to look first.

Why is my cache hit rate low?

Caching fails silently. You do not get an error; you just keep paying full price. The provider docs point at the same causes:

The fix for all of these is the same habit: read the usage fields your provider returns (Anthropic reports cache_read_input_tokens and cache_creation_input_tokens) and track the hit rate like any other production metric. If you are already investing in monitoring, our post on AI agent observability cost covers what to budget for it.

When is batch processing worth it?

If the answer is not needed immediately, such as classification of a backlog, nightly summarisation, bulk extraction or running an evaluation suite, batch APIs trade latency for price.

Anthropic's Message Batches documentation states a 50% cost reduction. A batch is limited to 100,000 requests or 256 MB, most batches finish within an hour, and a batch expires if not complete within 24 hours. The docs also say batch pricing and prompt caching discounts can stack, with the caveat that because requests are processed concurrently, cache hits are best-effort, with typical hit rates between 30% and 98% depending on traffic. For batches with shared context they suggest the 1-hour cache duration.

The rule of thumb: anything a user is not actively waiting for is a batch candidate. Anything interactive is not.

Should every request use your best model?

Probably not, but this is the lever to be most careful with, because it is the only one of the three that can degrade quality without telling you.

Routing means sending each task to the cheapest model that does that task well enough: a small model for classification, extraction and routing decisions, a larger one for open-ended reasoning and hard edge cases. The risk is obvious: "well enough" is a claim, and you need evidence for it.

A workable sequence:

  1. Write the evaluation set first. A few dozen to a few hundred real examples per task, with a pass/fail definition. Our AI agent evaluation framework post covers how to build one.
  2. Run the cheaper model against it. If it passes at the same rate, route to it. If it does not, you have a number to argue about instead of a feeling.
  3. Keep an escalation path. Let the small model hand uncertain cases to the large one rather than guessing.
  4. Re-run on every model change. Providers retire and replace models; a routing table is only as good as its last evaluation.

If fine-tuning a smaller model is on the table as a cost play, the volume maths is in RAG or fine-tuning: how to choose without burning a quarter.

What do the three levers cost on real models?

Listed prices per million tokens, from Anthropic's pricing page:

ModelInputOutput
Claude Opus 5.5$4$20
Claude Sonnet 5.5$2$10
Claude Haiku 5.5 (prompts up to 100K tokens)$0.10$0.50

Haiku 5.5 is a twentieth of Sonnet 5.5's list price — which is exactly why routing is worth the evaluation work. Putting the three levers side by side on one workload makes the gap concrete. This is an illustrative calculation on the list prices above, not a measured result from any client: 1,000 requests, each with a 6,000-token fixed prefix, 500 tokens of variable input and 300 tokens of output, on Sonnet 5.5. The cache write premium on the first request is ignored.

ScenarioInput costOutput costTotal
Baseline, no optimisation6.5M × $2 = $13.000.3M × $10 = $3.00$16.00
Prompt caching6M × $0.10 + 0.5M × $2 = $1.60$3.00$4.60
Batch only (50% off)$6.50$1.50$8.00
Same workload on Haiku 5.56.5M × $0.10 = $0.650.3M × $0.50 = $0.15$0.80

Caching alone takes this workload down by about 71%. Notice that output cost becomes the floor once input is cached — the $3.00 of output dominates the $4.60 total, which is why shorter outputs and structured formats matter more than they look. Whether the Haiku row is acceptable is an evaluation question, not an arithmetic one, and because batch jobs may not hit the cache the way interactive traffic does, measure the combination rather than multiplying the discounts.

What else adds to the bill?

What to do next

  1. Find your biggest stable prefix. System prompt, tools, reference material. Move everything that varies per request to the end.
  2. Turn on caching and watch the hit rate for a week before judging it.
  3. List your non-interactive workloads and move them to a batch API.
  4. Only then consider routing, and only with an evaluation set in place.

If you are building an AI product and want a second pair of eyes on where the tokens are going before you scale, our AI SaaS work covers architecture reviews like this one. Provider prices and model lineups change often, so treat every figure here as a snapshot and confirm against the current price sheet before you plan around it.

CodeKrypt avatar

CodeKrypt

Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write

Frequently asked questions

What is the fastest way to reduce LLM API costs?
Prompt caching, if your requests repeat a large stable prefix such as a system prompt, tool definitions or reference documents. Both Anthropic and OpenAI document cached-read prices at a fraction of the normal input price, and the change is mostly about how you order your prompt, not about changing models.
Why is my prompt cache hit rate low?
Usually because something that changes on every request sits near the front of the prompt, such as a timestamp, a user ID or reordered tool definitions. Caches match on an identical prefix, so one changed token early on invalidates everything after it. Put static content first and variable content last.
Can I combine batch processing with prompt caching?
On Anthropic's API, yes: the discounts stack. Cache hits inside batches are best-effort because requests are processed concurrently, and Anthropic's docs report typical hit rates between 30% and 98% depending on traffic.
Does cheaper model routing hurt quality?
It can, which is why routing needs an evaluation set first. Send a task to a smaller model only after you have measured that it passes the same checks as the larger one on that task.

Related reading

Chat on WhatsApp