Start free

Zero to FDE / Blog / LLM cost optimization: prompt caching, batching and model routing, with the numbers

Blog

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

LeverWhat it doesPublished price effect
Prompt cachingReuses a long prompt prefix across requests instead of paying full input price each timeA 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 APIRuns requests asynchronously, in bulk50% off both input and output tokens1,3
Model routingSends easy requests to a smaller modelClaude 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_control and 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 usage shows cache_read_input_tokens and cache_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

  1. Anthropic, “Pricing” (Claude Platform docs)
  2. Anthropic, “Prompt caching” (Claude Platform docs)
  3. Anthropic, “Batch processing” (Claude Platform docs)

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 free

More from the blog