Add a general `Caching` docs page covering how providers cache, cost, invalidation and monitoring
- Part of #6528 (slice D, the prompt caching contract page)
Turns docs/capabilities/caching.md into the general guide to prompt caching, structured like the Thinking page and retitled Caching. It tells users to add Caching() to their agents. Caching can't be on by default, because cache writes cost more than uncached input, but an agent without it pays full price on every request to providers that only cache when asked. The separate docs/prompt-caching.md this PR originally added is folded into the page. Each fact appears in one place.
Page outline:
- Intro: what prompt caching is; the prefix rule (a hit reuses an unchanged beginning of the current request; appending is fine, earlier changes break it); and the recommendation to add
Caching(), withmessages=Falsefor agents making one-off requests. - Unified caching settings:
Caching()and thecache=Trueequivalent, with a compact table of what it does per provider: nothing cached without it / implicit plus extra breakpoints / no effect. Subsections:- Configuring caching: values, retention (TTL) guidance, precedence,
cache=False. - Caching only the stable prefix: a runnable example with long shared instructions.
- Provider translation: the single place that says what the unified setting sends to each provider.
- Going beyond the unified setting: when to use
CachePointor provider-specific settings.
- Configuring caching: values, retention (TTL) guidance, precedence,
- How providers cache: native behavior and API-linked provider-specific settings for Anthropic, Bedrock, OpenAI, OpenRouter (including Gemini's fixed cached system instructions), Google (cached-content resources own instructions and tools) and other providers. Each links to the provider page's caching section.
- Cost, scoped to the providers whose write and read prices it lists.
- What invalidates a cache, including Anthropic thinking block binding, and Prefix-stability guarantees.
- Monitoring cache efficiency: a runnable check that compares two responses'
cache_write_tokensandcache_read_tokens(withmessage_history), usage fields, span signals, Warn On Cache Busts, a debugging order with links to the Anthropic and OpenAI cache diagnostics, and why no warning doesn't prove caching works. - Rules for extension authors, which are also kept in
capabilities/AGENTS.md.
Other changes:
- Agents page: a tip to add
Caching()to every agent. building-pydantic-ai-agentsskill:- The basic agent example includes
Caching(). - A Key Practices bullet says to add it by default.
- The caching reference uses
Caching(), adds retention guidance and a low-hit-rate debugging checklist, and notes that providers like Google ignoreCachePoint. COMMON-TASKS.mdgets a "Debug Low Cache Hit Rate" entry.
- The basic agent example includes
- Provider pages:
- The OpenAI page covers implicit caching and retention before GPT-5.6, and links the current
developers.openai.comguide anchors. - The Anthropic and Bedrock caching examples continue a conversation over a long shared document.
- The Bedrock page says
bedrock_cache_messagescan add a second cache point. - xAI sticky routing gets its own
#cache-sticky-routingsection.
- The OpenAI page covers implicit caching and retention before GPT-5.6, and links the current
- Logfire: an
unexpectedcollapse is described as a detected miss, not a diagnosed cause, with a pointer to the debugging order. - Warn On Cache Busts (page and README): the example combines
Caching()withWarnOnCacheBusts(), and the "never warns" scope now only coversCacheBustWarning. - Nav: removes the never-published
core-concepts/prompt-cachingentry, so no redirect is needed, and gives the page the aliasescachingandprompt-caching. - Tests:
tests/test_examples.pygets mock responses for the new runnable examples.
Every claim was checked against main: the unified-setting translation in each model class, precedence keys, the OpenAI GPT-5.6 gating, OpenRouter's Gemini tool-cache gate, Google ignoring CachePoint, bedrock_cache_messages adding the 20-block lookback point, and the instruction sort and prefix-stability tests.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code