Skip to main content
Prompt caching allows you to cache parts of your prompts that don’t change between requests, reducing costs and improving response times.

API Format

Both formats support the same caching functionality. The prompt_caching helper in the OpenAI format automatically converts to cache_control markers internally. Examples below are organized by format for clarity.

Pricing

Prompt caching uses a tiered pricing structure based on cache duration and usage type: The pricing multipliers are:
  • 5-minute cache writes: 1.25x the base input tokens price
  • 1-hour cache writes: 2x the base input tokens price
  • Cache reads: 0.1x the base input tokens price
Cache writes occur when content is first cached. Subsequent requests using the cached content are charged at the cache read rate (10% of base input price). The cache lifetime is refreshed each time the cached content is used.

Limitations

  • Maximum 4 cache breakpoints per request
  • Caches expire after 5 minutes by default
  • cache_control can only be inserted into text content blocks
Reserve cache breakpoints for large, static content like character cards, CSV data, RAG knowledge bases, book chapters, or extensive reference documentation.

Examples

System Message Caching

Anthropic Format (/v1/messages)

OpenAI Format (/v1/chat/completions)

User Message Caching

Anthropic Format (/v1/messages)

OpenAI Format (/v1/chat/completions)

Cache Control Options

Anthropic Format (/v1/messages)

string
required
Cache type. Currently only "ephemeral" is supported.
string
Time-to-live. Optional, defaults to 5 minutes. Format: "5m" or "1h".
Some models like claude-3-7-sonnet-20250219 do not support TTL in system messages. TTL is automatically stripped for these models.

OpenAI Format (/v1/chat/completions)

boolean
required
Enable prompt caching. Set to true to enable caching.
string
Time-to-live. Optional, defaults to "5m". Format: "5m" or "1h".
integer
required
Zero-based index of the last message to cache. All messages up to and including this index will be cached.
The prompt_caching helper automatically converts to cache_control markers in message content. You can also use cache_control markers directly in message content blocks (same as Anthropic format).

Using TTL

Specify cache duration with the ttl parameter:

Anthropic Format (/v1/messages)

OpenAI Format (/v1/chat/completions)

Usage Tracking

The API response includes cache usage in the usage object. Both endpoints return cache usage information:

Anthropic Format (/v1/messages)

OpenAI Format (/v1/chat/completions)

For cached requests, cache_read_input_tokens will be non-zero instead of cache_creation_input_tokens.
The OpenAI format uses prompt_tokens and completion_tokens instead of input_tokens and output_tokens, but the cache-related fields are identical across both formats.

Best Practices

  1. Cache large, static content that doesn’t change frequently
  2. Monitor cache_read_input_tokens to verify cache hits
  3. Respect the 4 breakpoint limit - prioritize largest, most reused content
  4. Remember cache expiration - caches expire after 5 minutes (or your TTL)
For more details, see the Anthropic documentation.