LLM cost optimization: prompt caching, batching and model routing, with the numbers
You can cut an LLM API bill with three levers: cache the part of the prompt that repeats, run work that can wait through a batch API, and send easy tasks to a cheaper model. The numbers below are Anthropic's published prices; other providers have similar features at different rates, so check theirs before you copy any figure.
The three levers
| Lever | What it does | Published price effect |
|---|---|---|
| Prompt caching | Reuses a long prompt prefix across requests instead of paying full input price each time | A 5-minute cache write costs 1.25x the base input price; a cache read costs 0.1x on most models and 0.05x on Claude Sonnet 5.51 |
| Batch API | Runs requests asynchronously, in bulk | 50% off both input and output tokens1,3 |
| Model routing | Sends easy requests to a smaller model | Claude Haiku 5.5 is listed at $0.10 / $0.50 per million input / output tokens, against $2 / $10 for Claude Sonnet 5.51 |
Anthropic also states that the caching multipliers stack with the batch discount.1 Routing is a design choice, not a setting, so test it with your evals first: a cheaper model is only cheaper if it still passes.
Prompt caching: what to know before you rely on it
- It pays back fast. Anthropic says a 5-minute cache saves money after one cache read.1
- It expires. The default lifetime is 5 minutes, and each hit refreshes it at no extra cost. A 1-hour option exists and costs 2x to write.2
- Short prompts are not cached. Below the model's minimum, the request runs without caching and no error is returned. For Sonnet 5.5 the minimum is 512 tokens; for some other models it is 1,024 to 4,096.2
- Order matters. You mark a block with
cache_controland the cache covers everything before it, so put the stable material (instructions, documents, tool definitions) first and the changing question last.2 This is the same discipline as context engineering. - Check that it works. The response's
usageshowscache_read_input_tokensandcache_creation_input_tokens. If both are zero, your prompt was probably below the minimum.2
A calculator you can run
This script prices 10,000 requests that share one 8,000-token prompt and return 300 tokens each, at Claude Sonnet 5.5's listed prices. It models one cache write, then cache reads, which assumes the calls arrive close enough together to keep the cache warm.
# Prices in US dollars per million tokens (Claude Sonnet 5.5, Anthropic pricing page).
IN, OUT = 2.00, 10.00
CACHE_WRITE = IN * 1.25 # 5-minute cache write
CACHE_READ = IN * 0.05 # cache hit on Sonnet 5.5
BATCH = 0.5 # batch discount on input and output
def cost(calls, prompt_tokens, out_tokens, cached=False, batch=False):
"""Total dollars for `calls` requests that share one long prompt."""
total = 0.0
for i in range(calls):
if cached:
rate = CACHE_WRITE if i == 0 else CACHE_READ # first call writes, the rest hit
else:
rate = IN
total += prompt_tokens * rate + out_tokens * OUT
total /= 1_000_000
return total * BATCH if batch else total
# 10,000 requests, each with the same 8,000-token prompt and a 300-token answer.
args = dict(calls=10_000, prompt_tokens=8_000, out_tokens=300)
base = cost(**args)
for name, kw in [("plain", {}), ("cached", {"cached": True}),
("batch", {"batch": True}), ("cached + batch", {"cached": True, "batch": True})]:
c = cost(**args, **kw)
print(f"{name:15} ${c:8.2f} {100 * (1 - c / base):4.0f}% cheaper")
Output:
plain $ 190.00 0% cheaper
cached $ 38.02 80% cheaper
batch $ 95.00 50% cheaper
cached + batch $ 19.01 90% cheaper
Two things to read from it. Caching saves 80% here, not 95%, because output tokens are not discounted and the 300-token answers still cost full price. And the result depends on the shape of the work: a long shared prompt with a short answer, the shape of a RAG app with a fixed instruction block, is the best case. Short, unique prompts gain almost nothing.
When the batch API does not fit
Anthropic lists the limits: batches are for work that does not need an answer right away, such as evaluations or bulk generation. Most finish in under an hour, but requests that do not finish within 24 hours expire, there is no streaming, and batches are not eligible for zero data retention or HIPAA.3 A user waiting in a chat window cannot use it; your nightly eval run can.
What this does not tell you
- Prices change. These are the figures on Anthropic's pages on 27 November 2026; check the current page before you quote a client.
- Newer Claude models use a tokenizer that Anthropic says produces about 30% more tokens for the same text,1 so compare cost per task, not just price per token.
- Cost is half of the picture. Track it next to quality with observability, so a saving that quietly lowers answer quality shows up.
Cost control is a normal part of taking an AI feature into production. Zero to FDE builds that skill step by step, but it is self-paced and written, and the course does not include live classes or mentors.
Zero to FDE is a self-paced 16-week course, ₹2,999 once, with a 7-day full refund. Week 1 is free, and one Week 4 lesson is free if you already write backend code. It has no live classes, no mentors and no accredited certificate.
Sources
Zero to FDE is a 16-week path, for working engineers and AIML graduates, to the work Forward Deployed Engineers do: backend basics, LLMs, RAG, agents, evaluation and deployment, with a shipped deliverable every week. Week 1 is free and complete, no card needed.
Start Week 1 freeMore from the blog
- Forward Deployed Engineer jobs in 2026: what the data says
- What is RAG? Retrieval-augmented generation, explained with working code
- What is an AI agent? The agent loop, explained with code
- AI engineer roadmap 2026: what to learn, and in what order
- Will AI replace software engineers? What the data says in 2026
- Forward Deployed Engineer courses in India (2026): fees, format and how they compare
- Forward Deployed Engineer vs ML engineer: which AI role fits you?
- Forward Deployed Engineer salary in India: what the 2026 data says for 2027
- Forward Deployed Engineer interview questions: the six rounds and how to answer
- Why Forward Deployed Engineer is a smart next move for a software engineer
- Forward Deployed Engineer certification in 2026: what exists, what it costs, and what employers check
- Forward Deployed Engineer skills: what 1,000 job posts ask for
- Forward Deployed Engineer vs Solutions Engineer: the real difference
- Forward Deployed Engineer resume: what to put on one page
- Forward Deployed Software Engineer (FDSE): what the Palantir title means
- Forward deployed AI engineer, AI deployment engineer, FDE: the titles explained
- Prompt injection explained: what it is and how to defend against it
- Context engineering explained: beyond prompt engineering
- RAG vs fine-tuning: which one to use, and when
- LLM evals explained: how to test a system that gives different answers
- LLM observability explained: traces, cost and what to log
- Tool calling explained: how an LLM uses your functions
- What is MCP? The Model Context Protocol explained
- AI agent vs workflow: which one does your problem need?
- AI engineer vs ML engineer: what each one does
- AI engineer interview questions: 25 that test whether you have built anything
- What is a vector database? Explained with a 30-line example
- EY now hires Forward Deployed Engineers for audit. The role is leaving the AI labs
- LangGraph explained: state, nodes and edges, with a 30-line example
- Randstad: 90% of Indian employers are growing tech teams for AI. What it means for engineers
- AI agent memory explained: short-term vs long-term, with a tested example
- Structured outputs from an LLM: JSON schema, validation and retries
- Embeddings explained: vectors, cosine similarity and dimensions
- Data engineer to AI engineer: what carries over and what to learn
- AWS launches a Forward Deployed Engineering Competency, with Infosys, TCS and Coforge among 22 launch partners
- Forward Deployed Architect: what the role is, certifications and courses
- Persistent launches a Forward Deployed Engineering program with Microsoft, a day after NIIT's FDE talent blueprint
- How to become an AI engineer in India: the route depends on where you start
- Self-paced Forward Deployed Engineer courses in India under ₹10,000 (and under ₹3,000)
- AWS and OpenAI will jointly staff forward deployed engineering teams inside customer environments
- Backend developer to AI engineer: what carries over and what to learn
- Claude now runs on premises in customers' own data centers through AWS AI Factories
- Agentic AI courses compared: four free options, and what a course must make you build
- AWS: attacks on AI systems grew about 800% in 2026, and an AI agent broke into a decoy MCP server in 12.7 minutes