Prompt Caching for AI Agents — How to Cut Latency and Cost
Set up prompt caching for AI agents to cut both cost and latency — cache breakpoints, TTL tradeoffs, and cache-friendly prompt structuring.

Prompt caching is one of the few AI agent optimizations that improves both cost and latency simultaneously with no tradeoff — but only if the prompt is structured so the cache actually hits. Here's how to set it up correctly.
Step 1: Understand What Actually Gets Cached
Caching stores a processed representation of a prompt prefix — everything up to a designated breakpoint. A later call with the identical prefix skips reprocessing those tokens.
The cache_control marker tells the API where the cacheable prefix ends. Everything before it needs to be byte-for-byte identical across calls for the cache to hit.
Step 2: Structure Prompts With Static Content First
Any value that changes between calls — a timestamp, a request ID, dynamic user context — invalidates the cache for that entire request if it sits before the breakpoint. Moving dynamic content to the end of the prompt, after everything cacheable, is what keeps the cache hit rate high.
Step 3: Cache Tool Definitions and Large Reference Documents Too
Tool definitions are often static across an entire agent session and can be sizable (many tools with detailed schemas) — caching them separately from the system prompt captures the same savings for content that's just as repetitive.
Step 4: Account for Cache TTL in Agent Loops
Default cache TTLs are short (commonly around 5 minutes of inactivity). If an agent's loop includes a slow tool call — a long-running search, a large file operation — the gap between one model call and the next can exceed the TTL, silently reverting to full-price, full-latency processing on the next turn.
Step 5: Measure Cache Hit Rate, Not Just Assume It's Working
A prompt restructure that looks correct in code can still fail to cache in practice — for example, a tool list assembled in a different order on each call (from a set or dict without stable ordering) produces a different byte sequence every time even though the content is logically the same. Measuring the actual hit rate is the only way to confirm caching is working as intended.
Step 6: Know When Caching Doesn't Help
Caching pays off in proportion to how much static content is repeated across how many calls. A one-shot request with a short system prompt has little to gain; a multi-turn agent loop reusing a large system prompt and tool catalog across dozens of calls is exactly the shape caching is built for.
Key Takeaways
Prompt caching only helps when the cached prefix is byte-for-byte identical across calls, which means static content (system prompt, tool definitions) needs to come before any dynamic, per-request content in the prompt structure, cache TTLs are short enough that slow tool calls in an agent loop can silently cause cache misses, and measuring actual cache hit rate — not just assuming a correct-looking implementation is working — is the only way to confirm the savings are real.






