prompt-caching-patterns

Installation
SKILL.md

Prompt Caching Patterns

Anthropic's prompt caching cuts input-token cost by ~90% on cached prefixes and reduces latency. Worth learning because one mistake (putting a dynamic value before a stable prefix) disables the whole cache.

Cache Mechanics

  • TTL: default 5 minutes; ttl: "1h" for 1-hour cache (higher base cost but longer-lived).
  • Minimum size: 1024 tokens per cache block for Sonnet/Opus, 2048 for Haiku.
  • Max breakpoints: 4 per request.
  • Order matters: everything BEFORE a cache_control block is part of that cache key. Dynamic content AFTER the cached block doesn't break the cache.

Anatomy of a Cached Request

from anthropic import Anthropic
Installs
6
GitHub Stars
175
First Seen
May 16, 2026
prompt-caching-patterns — softspark/ai-toolkit