{
  "slug": "prompt-caching-for-agents",
  "title": "Prompt Caching for AI Agents",
  "description": "Cross-provider prompt caching reference: how to activate it, minimum token thresholds, TTLs, read-vs-write pricing, and when it pays off for agentic workloads.",
  "category": "Guide",
  "tags": [
    "prompt-caching",
    "cost",
    "latency",
    "anthropic",
    "openai",
    "gemini",
    "agents",
    "optimization"
  ],
  "updated": "2026-07-22",
  "canonical": "https://changegamer.ai/resources/prompt-caching-for-agents",
  "markdown": "https://changegamer.ai/resources/prompt-caching-for-agents.md",
  "outline": [
    {
      "depth": 2,
      "text": "When does caching pay off?",
      "anchor": "when-does-caching-pay-off"
    },
    {
      "depth": 2,
      "text": "How to trigger caching (by provider)",
      "anchor": "how-to-trigger-caching-by-provider"
    },
    {
      "depth": 2,
      "text": "Cross-provider comparison",
      "anchor": "cross-provider-comparison"
    },
    {
      "depth": 2,
      "text": "Structuring prompts to maximize cache hits",
      "anchor": "structuring-prompts-to-maximize-cache-hits"
    },
    {
      "depth": 2,
      "text": "Stacking with batch discounts",
      "anchor": "stacking-with-batch-discounts"
    },
    {
      "depth": 2,
      "text": "Verified sources",
      "anchor": "verified-sources"
    }
  ],
  "related": [
    {
      "slug": "agent-cost-latency-optimization",
      "title": "Agent Cost and Latency Optimization",
      "description": "Practitioner reference for reducing the cost and latency of production AI agents: the compounding model, token-level levers (caching, pruning), request-level levers (Batch API, parallelism), model-level levers (routing, reasoning-effort controls), and architecture-level levers (step reduction, semantic caching, code offloading).",
      "url": "https://changegamer.ai/resources/agent-cost-latency-optimization"
    },
    {
      "slug": "streaming-for-agents",
      "title": "Streaming Responses for Agents",
      "description": "Transport formats, provider event schemas, and practical concerns for consuming streamed LLM responses in production agents: SSE mechanics, OpenAI (Chat Completions and Responses API) and Anthropic event formats, partial-JSON tool-call parsing, backpressure, cancellation, and gateway proxying.",
      "url": "https://changegamer.ai/resources/streaming-for-agents"
    },
    {
      "slug": "agent-response-caching",
      "title": "Application-Level Response Caching for AI Agents",
      "description": "How to implement exact-match and semantic caching in your agent application to eliminate redundant LLM calls, with threshold guidance, invalidation strategies, and a decision matrix for when semantic caching is unsafe.",
      "url": "https://changegamer.ai/resources/agent-response-caching"
    },
    {
      "slug": "computer-use-browser-automation",
      "title": "Computer Use and Browser Automation for Agents",
      "description": "Two-layer reference: vendor computer-use APIs (Anthropic, OpenAI CUA, Google Gemini) that translate screenshots to actions, and the open harnesses (Playwright MCP, browser-use, Stagehand, Skyvern) that execute those actions — with loop mechanics, reliability tradeoffs, and security gates.",
      "url": "https://changegamer.ai/resources/computer-use-browser-automation"
    }
  ],
  "body": "Prompt caching lets the provider reuse the KV-cache from a prior request when the leading prefix of a new request matches one it has already processed. Repeated tokens are read at a fraction of the standard input price instead of being recomputed. For agents that send the same system prompt, tool definitions, or reference documents on every loop iteration, caching is the single highest-ROI cost lever available. See /resources/agent-cost-latency-optimization for the broader optimization stack.\n\n## When does caching pay off?\n\n**Caching pays off when:**\n\n- A large, stable block (system prompt, tool schemas, RAG chunks, few-shot examples) repeats across many requests within the TTL window.\n- The stable prefix exceeds the provider minimum (roughly 1,024–2,048 tokens depending on provider and model).\n- Requests arrive frequently enough that write cost is amortized over multiple cache reads within the TTL.\n- Agent loop step count is high — savings compound linearly with the number of calls.\n\n**Caching does not pay off when:**\n\n- Every request has a different prefix (no stable leading block).\n- Request volume is very low — a single cache read may not recoup the write premium.\n- The TTL expires between requests (e.g., batch jobs spaced hours apart).\n- Output tokens dominate cost — caching only discounts input tokens.\n\n## How to trigger caching (by provider)\n\n**Anthropic (Claude)** — manual activation. Place a `cache_control` field on a content block to mark the cache breakpoint (up to 4 breakpoints per request):\n\n```json\n{ \"type\": \"text\", \"text\": \"...long stable context...\",\n  \"cache_control\": { \"type\": \"ephemeral\" } }\n```\n\nThe default TTL is 5 minutes; a 1-hour TTL is available via `\"ttl\": \"1h\"`. Confirm a cache hit by reading `cache_creation_input_tokens` and `cache_read_input_tokens` in the response `usage` object. Cache reads are billed at a large discount versus base input; cache writes carry a modest premium (higher for the 1-hour TTL). Verify the current multipliers and per-model minimum cacheable tokens in the pricing docs.\n\n**OpenAI (GPT-4o and later)** — fully automatic, no code change. Caching activates when the prompt is 1,024 tokens or longer; the API caches the longest matching prefix in 128-token increments. Cached counts appear in `usage.prompt_tokens_details.cached_tokens`.\n\n**Google Gemini** — two modes. *Implicit caching* (Gemini 2.5+) is automatic with no code, with a minimum of roughly 2,048 tokens. *Explicit context caching* creates a named cache object with a configurable TTL (default ~60 minutes) referenced by ID; it adds a storage cost per cached-token-hour. Use explicit caching when you need guaranteed reuse.\n\n**DeepSeek** — automatic prefix caching applied when requests share a common prefix from token 0 (no partial mid-input matches). Cache-hit input is priced far below cache-miss; exact thresholds and rates are not consistently documented — verify in your billing dashboard.\n\n## Cross-provider comparison\n\n| Provider | Activation | Min tokens | TTL | Read discount | Notes |\n|---|---|---|---|---|---|\n| **Anthropic Claude** | Manual (`cache_control` breakpoints) | ~512–4,096 (model-dependent) | 5 min default, 1 h opt-in | Large (cache read ≈ 0.1× base input) | Write carries a premium (higher for 1 h); up to 4 breakpoints |\n| **OpenAI GPT-4o+** | Automatic (prefix-based) | 1,024 | ~5–10 min idle (longer for some models) | Significant on cached prefix (verify per model) | Caches in 128-token increments; no explicit controls |\n| **Google Gemini 2.5+** | Implicit (auto) or explicit (named cache) | ~2,048 | Implicit: opportunistic; Explicit: ~60 min, configurable | Large on cached read | Explicit caching adds a per-cached-token-hour storage cost |\n| **DeepSeek** | Automatic (exact prefix from token 0) | Not officially documented | Not officially documented | Large cache-hit discount | Exact-prefix match only; verify current pricing |\n\nExact discount percentages and minimum-token thresholds change per model and over time — treat this table as directional and confirm against each provider's current pricing docs (linked below) before relying on a figure.\n\n## Structuring prompts to maximize cache hits\n\n1. **Stable content at the top.** Put the system prompt, tool schemas, and reference documents before any dynamic content — cache matching is prefix-based.\n2. **Dynamic content at the tail.** User messages, current task context, and retrieved chunks go after the cache breakpoint.\n3. **Keep stable blocks stable.** Any edit to a cached block invalidates the cache; treat cached content as immutable across a session.\n4. **Monitor hit rates.** All major providers expose cache-read token counts in the usage response. Track cache_read_tokens / total_input_tokens per endpoint; a low ratio for an agent with a stable system prompt signals missed opportunities.\n\nFor prompt-structure principles that interact with caching, see /resources/prompt-context-engineering.\n\n## Stacking with batch discounts\n\nPrompt caching and a batch API (50% off all tokens — see /resources/handling-rate-limits-and-retries) stack independently: a batched request that hits cache pays the batch rate on uncached tokens and the cache-read rate on cached tokens — the cheapest combination for non-latency-sensitive work.\n\n## Verified sources\n\n- Anthropic prompt caching docs: https://platform.claude.com/docs/en/build-with-claude/prompt-caching\n- Anthropic pricing (cache write/read multipliers): https://platform.claude.com/docs/en/about-claude/pricing\n- OpenAI prompt caching announcement: https://openai.com/index/api-prompt-caching/\n- Google Gemini implicit caching announcement: https://developers.googleblog.com/en/gemini-2-5-models-now-support-implicit-caching/\n- Google Gemini context caching docs: https://ai.google.dev/gemini-api/docs/caching\n- DeepSeek context caching guide: https://api-docs.deepseek.com/guides/kv_cache",
  "sources": [
    "https://platform.claude.com/docs/en/build-with-claude/prompt-caching",
    "https://platform.claude.com/docs/en/about-claude/pricing",
    "https://openai.com/index/api-prompt-caching/",
    "https://developers.googleblog.com/en/gemini-2-5-models-now-support-implicit-caching/",
    "https://ai.google.dev/gemini-api/docs/caching",
    "https://api-docs.deepseek.com/guides/kv_cache"
  ]
}