What you need to know
Diagnose first
Split spend into input, output, cache write and cache read tokens, and into request volume versus tokens per request. Each driver has a different fix.
| Driver | Optimization |
|---|---|
| Repeated input prefix (system prompt, tools, documents) | Prompt caching |
| Work nobody needs immediately | Message Batches API (about 50% off) |
| Long outputs nobody needs | Length instructions and max_tokens budgets |
| Large tool sets on every request | Tool search for rarely used tools |
| Simple requests on a large tier | Route to a smaller tier (see 5.2) |
How caching works
- A
cache_controlbreakpoint caches the exact prefix up to it, in the order tools, system, messages. - Reads cost about 10% of normal input; writes cost 1.25x (five-minute lifetime) or 2x (one-hour lifetime).
- Up to four breakpoints; prefixes below a minimum length are not cached.
- Anything that changes before a breakpoint (timestamp, request ID, user name) makes every prefix unique. A change to tools invalidates everything cached after them.
Breakpoint patterns
| Pattern | Where breakpoints go | Fits |
|---|---|---|
| Single | After the stable system prompt and tools | One shared prefix, varied questions |
| Layered | After the stable prefix, then after content that changes on a slower cadence (a customer's contract) | Prefixes reused on different schedules |
| Rolling | On the latest message each turn | Multi-turn chats, so the growing history is reused |
Batch and budgets
Batch suits nightly classification, re-scoring and bulk extraction: about half the price, results within 24 hours, matched by custom_id. For output-heavy features, a precise length instruction plus max_tokens cuts the largest line on the bill.
In the exam
Items show usage or cost data and a request layout, and ask for the dominant driver, the right optimization or the expected effect. Decompose the cost, then place breakpoints after stable content (layered or rolling where needed), batch what can wait, and budget long outputs. Distractors extend cache lifetimes for prefixes that never match, cache a changing timestamp, batch interactive traffic, or shrink the model regardless of quality.
Check your understanding
92% of spend is input; every request repeats a 12,000-token system prompt and tools. Fix?
Show answer
Answer: C. Repeated input prefixes are exactly what caching targets.
Cache reads are zero; the cached system prompt includes the current timestamp. Fix?
Show answer
Answer: B. Changing text before the breakpoint prevents every match.
Multi-turn chats cache only the system prompt; input grows with each turn. Which pattern?
Show answer
Answer: D. Each turn then reuses the previously cached conversation.
Apply it: Cut Juniper's agent cost
Juniper's agent costs about $0.09 per conversation; input is 85% of spend. Each request sends 9,000 tokens of system prompt and tool definitions, then the conversation (average 6 turns), then a 2,000-token customer-order summary that changes per conversation. The review classifier runs realtime at 2 a.m.
- Identify the driver and design the breakpoints.
- Estimate the saving on the 9,000-token prefix for a 6-turn conversation, using the case's cache prices and Tier S (the agent's current tier).
- Fix the classifier's cost.
Done when: every breakpoint sits after content that repeats exactly.
Show model answer
1. Repeated input. Move the order summary to the start of the conversation (after the stable prefix) rather than resending it after every turn; breakpoint 1 after the system prompt and tools (shared by all conversations); breakpoint 2 after the order summary (shared by that conversation's turns); a rolling breakpoint on the latest message each turn.
2. Without caching, the prefix is sent six times: 54,000 tokens x $1 per million = $0.054 per conversation, more than half of the $0.09. With the prefix warm (it is shared by every conversation, so it stays cached), the same 54,000 tokens are reads at $0.10 per million = $0.0054. That saves about $0.049 per conversation, roughly 90% of the prefix cost, before the rolling cache on history.
3. Move the classifier to the Message Batches API, on Tier S if its evaluation passes: about half price from batch alone.