Anthropic Prompt Caching logo

Anthropic Prompt Caching

Free

Prompt prefix

FreeFree tier
Inputs: textOutputs: text
Type
Open Source
Company
Anthropic

About Anthropic Prompt Caching

Prompt caching optimizes your API usage by allowing resuming from specific prefixes in your prompts. This significantly reduces processing time and costs for repetitive tasks or prompts with consistent elements. There are two ways to enable prompt caching: Automatic caching uses a single cache_control field and the system automatically applies the cache breakpoint to the last cacheable block, best for multi-turn conversations. Explicit cache breakpoints give fine-grained control by placing cache_control on individual content blocks.

Key Features

Automatic caching of prompt prefixes
Explicit cache breakpoints for fine-grained control
Reduces processing time and costs
Ephemeral caching type
Works with multi-turn conversations

Pros & Cons

Pros
  • Significantly reduces API processing time and costs
  • Easy to enable with automatic caching
  • Provides fine-grained control with explicit breakpoints
  • Works seamlessly with multi-turn conversations
Cons
  • Cache is ephemeral and may be cleared over time

Best For

Prompts with many examplesLarge amounts of context or background informationRepetitive tasks with consistent promptsMulti-turn conversations

FAQ

How does prompt caching work?
When you send a request with prompt caching enabled, the system checks if a prompt prefix (up to a specified cache breakpoint) is already cached from a recent query. If found, it uses the cached version, reducing processing time and costs. Otherwise, it processes the full prompt and caches the prefix once the response begins.
What are the two ways to enable prompt caching?
Automatic caching: Add a single cache_control field at the top level of your request; the system automatically applies the cache breakpoint to the last cacheable block and moves it forward as conversations grow. Explicit cache breakpoints: Place cache_control directly on individual content blocks for fine-grained control over exactly what gets cached.
When is prompt caching especially useful?
Prompt caching is especially useful for prompts with many examples, large amounts of context or background information, and repetitive tasks with consistent elements.