Skip to main content
Enable response and prompt caching to improve performance and reduce API costs.

Quick Start

1

Simple Enable

Enable caching with defaults:
2

With Configuration

Configure caching behavior:

Configuration Options

What gets cached

  • System block: instructions, tools, and memory prelude
  • Stable conversation-history prefix (Anthropic only) — the two most recent messages stay uncached

Common Patterns

Pattern 1: Full Caching

Pattern 2: Auto-Detection with Memory

Even without explicit prompt_caching=True, the SDK auto-detects model support and arranges the prefix accordingly:

Pattern 3: Disable Caching


Best Practices

Anthropic Claude supports prompt caching for significant cost savings on repeated prompts.
Turn off caching when agents need fresh, real-time information.

Performance

Performance optimization tips

ExecutionConfig

Execution limits configuration