The two techniques that turn a $500/day API bill into $190. One saves money on every request. The other saves money by not rushing.
Same system prompt, a thousand times a day, Cache the prefix once, don't make the model repay. Batch the offline jobs, let the queue run deep — Half the price, same results. That's margin you keep.
I What Is Prompt Caching?
Part 2 introduced prompt caching as one of five optimization levers. Time to open the hood.
Here's the problem: every API request includes a system prompt. Your product's personality, instructions, few-shot examples, retrieval context — all of it gets sent on every single call. And every single time, the model processes it from scratch. That's like reciting the company handbook before every conversation.
Prompt caching stores the model's processed representation of your static contextso it doesn't have to recompute it. The technical term is "KV-cache" — the key-value pairs the model generates internally when it reads your input. On the first request, the model processes your system prompt and saves the result. On subsequent requests with the same prefix, it skips straight to the new part.
Key Insight
This is not output caching.You're not storing the model's answers. You're storing the model's understanding of your instructions. Every response is still freshly generated — it just starts from a warmer position. The analogy: a teacher who's already read the textbook doesn't need to re-read it before answering each student's question.
The payoff is immediate and measurable: 40-90% savings on input token costs and dramatically reduced Time to First Token (TTFT). For a product sending thousands of requests with a 2,000-token system prompt, this is the single highest-ROI optimization you can make.
II How It Actually Works
The mechanics are straightforward, which is part of what makes this so powerful — there's almost no reason not to use it if your prompts have a stable prefix.
Step 1: First request.You send your full prompt — system instructions, few-shot examples, retrieval context, then the user's message. The model processes everything, generating an internal representation (the KV-cache) as it reads. The provider stores this representation, keyed to your exact prefix.
Step 2: Subsequent requests. You send the same prefix plus a new user message. The provider recognizes the prefix, loads the cached KV-cache, and the model only has to process the new tokens. The static portion is essentially free.
Step 3: Billing.Cached input tokens are billed at a steep discount — typically 75-90% off. So a 2,000-token system prompt that normally costs $3/million tokens might cost $0.30-$0.75/million when cached. The non-cached portion (the user's actual message) is billed at the normal rate.
Analogy
Think of it like a restaurant kitchen. Without caching, every order starts from raw ingredients — even if 80% of the dish is the same base sauce you've made a hundred times today. With caching, the base sauce is prepped once and kept warm. Each new order only requires the unique finishing touches. Same dish, fraction of the prep time.
There are constraints. The cache has a TTL (time to live)— typically 5-10 minutes of inactivity before it's evicted. The prefix must match exactly, byte for byte. Change a single character in your system prompt and you get a cache miss. And there's usually a minimum token threshold (e.g., 1,024 tokens) before caching kicks in.
III When to Cache (and When Not To)
Prompt caching isn't a universal win. It's a powerful one, but like every optimization, it has a sweet spot.
Cache when:
Your system prompt is large and stable. A 2,000-token instruction set that changes once a month? Cache it. The bigger the static portion relative to the dynamic portion, the bigger the savings.
You use few-shot examples.Those five carefully crafted input-output pairs you send with every request are perfect cache candidates. They're substantial, they're identical across calls, and they're expensive to reprocess.
RAG context is shared across a session. If a user is asking multiple questions about the same retrieved document, the document stays in cache between turns. The second question about the same context is dramatically cheaper than the first.
You have high request volume. Caching has the most impact when many requests share the same prefix. A product handling 10,000 requests/hour with the same system prompt sees enormous savings. A product handling 10 requests/hour with unique prompts sees almost none.
Don't cache when:
Every request is unique.If the entire prompt changes with each call — no shared system prompt, no repeated examples — there's nothing to cache.
Context changes frequently.If your system prompt updates every few minutes (real-time data feeds, frequently rotated instructions), the cache will miss more than it hits and you'll pay the write cost without the read benefit.
Prompts are short.A 200-token system prompt saves so little when cached that it's not worth thinking about. Focus your optimization energy elsewhere.
Builder Tip
Structure your prompts for cacheability. Put static content first (system instructions, few-shot examples, shared context) and dynamic content last (user message, session-specific data). This maximizes the cacheable prefix. A prompt structured as [system + examples + user message] caches beautifully. A prompt structured as [user context + system instructions + user message] caches poorly because the prefix changes every time.
IV Batching: The Other Lever
Caching optimizes the per-request cost. Batching optimizes the throughput cost — and it works on a completely different principle.
Batch APIs let you send hundreds or thousands of requests in a single API call and get results back asynchronously — usually within 24 hours. In exchange for giving up real-time responses, you get a massive discount: typically 50% off the standard per-token price.
Why the discount? Because the provider can schedule your batch during off-peak hours, fill GPU capacity gaps, and optimize throughput without latency constraints. You're trading urgency for efficiency — and the provider passes the savings through.
Best for:
Eval harnesses.Running 500 test cases against your prompt? That's a perfect batch job. You don't need results in milliseconds — you need them by morning.
Bulk processing.Classifying 10,000 support tickets, summarizing a quarter's worth of call transcripts, generating product descriptions for a catalog. High volume, low urgency.
Offline analysis.Weekly reports, content moderation backlogs, data enrichment pipelines. Anything where the consumer of the output is a system or a human who'll look at it later.
Dataset generation.Creating synthetic training data, generating test fixtures, building evaluation sets. Volume matters, speed doesn't.
Bad for:
Anything user-facing and real-time.If a human is waiting for the response, batch is not the answer. A 24-hour SLA on a chatbot response is called "email."
Interactive workflows.If the next step depends on the model's output, you can't batch because you need the result to continue.
Key Insight
Caching and batching are complementary, not competing. Caching reduces per-request cost for real-time traffic. Batching reduces cost for offline workloads. A well-architected product uses both — caching for the user-facing API calls and batching for the nightly eval runs, weekly reports, and bulk processing jobs. The 2025 coding tools ecosystem generated over $1 billion in revenue (per a16z). At that scale, shaving 50% off batch processing costs is the difference between healthy margins and lighting money on fire.
See which approach fits your use case:
Decision tool
Batch vs. Real-Time
Select your use case to see whether batching, caching, or standard API calls are the right fit.
Select a use case above
Latency sensitivity
Volume
Prefix stability
V The Cost Math
Theory is nice. Let's do the arithmetic.
Scenario:You're running a customer support product. 50,000 requests per day. Each request includes a 2,000-token system prompt (instructions + few-shot examples) and a 300-token user message. Average output: 200 tokens. You're using a Sonnet-class model ($3/M input, $15/M output).
Without caching:
Input cost: 50,000 requests x 2,300 tokens x $3/M = $345/day
Output cost: 50,000 x 200 tokens x $15/M = $150/day
Total: $495/day ($14,850/month)
With prompt caching (2,000 tokens cached at 90% discount):
Cached input: 50,000 x 2,000 tokens x $0.30/M = $30/day
Non-cached input: 50,000 x 300 tokens x $3/M = $45/day
Output cost: unchanged at $150/day
Total: $225/day ($6,750/month)
That's a ~78% reduction on the input side (about 55% off the total bill) and $8,100/month saved — from a configuration change that takes an afternoon to implement.
Now layer on batching for your offline workloads. Say 30% of your traffic is non-urgent (ticket classification, weekly summaries, eval runs). Move those to batch at 50% off:
Real-time (70%): $225/day x 0.7 = $157.50/day
Batch (30%): $225/day x 0.3 x 0.5 = $33.75/day
Combined: $191.25/day ($5,738/month)
From $495/day to $191/day. A 61% total reduction.And you haven't changed a single word of your prompts or switched models.
Play with your own numbers:
Calculator
Cache Savings Calculator
Input your request volume and prompt structure to see how much caching and batching can save.
50,000
2,000
300
200
0%
Without caching
$495/day
→
With caching + batching
$225/day
You save $270/day (55% reduction). That's $8,100/month — from configuration changes alone.
VI Implementation Patterns
Understanding the theory is step one. Shipping it well requires attention to a few practical patterns.
1. Structure prompts for cache-friendliness. The golden rule: static content first, dynamic content last. Your prompt should be layered like this:
System instructions — personality, rules, output format. Changes rarely.
Shared context — retrieved documents, session context. Changes per session.
User message — the actual request. Changes every call.
Everything above the user message is your cacheable prefix. The longer and more stable that prefix is, the more you save.
2. Cache warming.The first request always pays full price (no cache exists yet). For high-volume products, send a "warming" request at startup or after deploys to prime the cache before real traffic hits. This is especially important if your system prompt is large — you don't want your first 100 users paying the full processing cost when a single warm-up call would have covered everyone.
3. TTL management. Cache entries expire after a period of inactivity (typically 5-10 minutes). If your traffic is bursty — heavy during business hours, dead overnight — the cache will go cold every night. Consider a lightweight keep-alive request during low-traffic periods if the cache warming cost is significant. But do the math first: if your nightly traffic is 10 requests, warming the cache costs more than just paying the full price.
4. Monitor cache hit rates.You can't optimize what you don't measure. Track:
Cache hit rate — what percentage of requests use the cache? Below 80% means something is wrong with your prefix stability.
Cost per request (cached vs. uncached) — to quantify actual savings.
TTFT reduction— cache hits should reduce time to first token by 30-80%. If they don't, verify the cache is working.
5. Version your prompts carefully.A single character change in your system prompt invalidates the cache. Use a deployment process that changes prompts deliberately, not accidentally. A stray newline in a config file shouldn't double your API costs overnight.
Builder Tip
The best implementation strategy is boring: enable prompt caching on day one (it's usually a flag or a small API parameter change), structure your prompts with static prefixes, monitor your hit rate, and move offline workloads to batch. There's no trick. Anthropic's data shows roughly 50% of all agentic tool calls are software engineering tasks — a single concentrated use case generating enormous request volume. For products like that, these two optimizations alone can be worth six figures annually.
Takeaway
Prompt caching and batching are the unglamorous optimizations that separate a prototype from a product. Caching stores the model's processed understanding of your static context, saving 40-90% on input costs with almost no implementation effort. Batching trades real-time responses for 50% cost savings on offline workloads. Combined, they can cut your API bill by 50-70% — without changing a single word of your prompts, switching models, or sacrificing output quality. If you remember one thing: static prefix first, dynamic suffix last, batch what can wait.
Test your understanding
Article Recap
5 questions covering the key concepts from this article.
1 of 5
Your product sends a 2,500-token system prompt with every request. An engineer asks: "Should we enable prompt caching?" What's the right framing for the decision?