For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Prompt caching

Reduce latency and cost with prompt caching.

Why prompt caching matters

Prompt caching reuses work when requests share the same prompt prefix. This provides three main benefits:

  • Compute-efficient: Avoid recalculating a prompt prefix that the model has already processed.
  • Cheaper input tokens: Pay the model’s reduced cached-input rate for reused tokens, discounted up to 90%.
  • Faster: Reduce the time spent processing input before the response starts.

Prompt caching is enabled by default for supported OpenAI models. Use the Prompt Caching Dashboard to monitor cache read hit rates.

What is the prompt cache?

As the model processes input tokens, it calculates intermediate key-value (KV) states. These states let the model refer back to earlier tokens while processing new input and generating a response.

Prompt caching preserves that state for a reusable prefix. When a later request has the same prefix and finds a matching cache entry, the model can reuse the saved state instead of processing those tokens again. It still needs to process any new input to generate a new response.

The prompt cache stores key-value (KV) tensors, not the tokens themselves.

Ask ChatGPT for a deeper explanation

OpenAI caches the model’s full rendered context including OpenAI-provided instructions, developer messages, tool definitions, and conversation history containing text, images, documents, and supported audio.

Cache reuse requires the entire rendered prefix to match. If content or a relevant setting changes before a breakpoint, the prefix after that change cannot match the existing cache entry.

How caching works

A cache breakpoint marks the end of a prompt prefix that OpenAI can save to the cache and reuse in later requests. The first request writes an eligible prefix to the cache and a later request looks for the longest matching cached prefix available, working backward through eligible breakpoints until it finds a match.

A prompt prefix must meet the model’s minimum cacheable token length before it can be cached. Tokens in the OpenAI-provided hidden system content do not count toward this minimum. The minimum cacheable prompt length is 1,024 tokens for GPT-5.6 and later and 2,048 tokens for models older than GPT-5.6. You may occasionally get cache hits below 2,048 tokens for some earlier models. See the model comparison for other differences.

After the minimum cacheable token length, you can choose where to place cache breakpoints explicitly, or let OpenAI choose their locations implicitly. The available options depend on the model.

Model generation
Caching mode

Implicit breakpoints are placed at the latest eligible user message.

Hidden systemToolsDeveloperContext historyFollow-upCached inputUncached input
Minimum cacheable length (varies by model)

Request 1

12,000 input tokens
3,000 tokens(illustrative)

Request 2

15,000 input tokens
3,000 tokens(illustrative)
0
2.5k
5k
7.5k
10k
12.5k
15k
17.5k
20k
Input tokens (including illustrative hidden tokens)
15,000
Last matched breakpoint
3,000
Hidden tokens
=
12,000
Reported cached tokens

Cache lifetime

Cache entries are not stored indefinitely. A later request can reuse a cached prefix only while its entry remains available, and reusing the prefix refreshes its lifetime without another cache-write charge. The lifetime and retention settings depend on the model.

Cache location

Cached states live on individual machines, where traffic above 15 requests per minute can lead to overflow routing. A request can reuse a cached prefix only if it reaches a machine holding a matching entry that has not expired. Routing requests to the right machine is therefore important for cache reuse.

Caches are not shared across organizations and cannot be reused across regional processing boundaries.

OpenAI handles routing automatically. Within an organization and processing region, routing for a given model depends on:

  • Current machine load and available capacity.
  • A hash of the initial tokens after the hidden OpenAI content, including tool definitions when present. The number of tokens hashed varies by model.
  • The optionally supplied prompt_cache_key that controls grouping and distribution during higher-volume traffic, to mitigate request overflow to other machines and, therefore, cache misses.

Summary of model differences

BehaviorGPT-5.6 and laterGPT-5.5 and GPT-5.5 ProOther earlier models
Implicit breakpointsAt the end of the latest eligible user or tool message.Spaced at regular 2,048-token intervals.Spaced at regular, model-dependent intervals.
Explicit breakpointsSupportedNot supportedNot supported
Minimum cacheable prefix1,024 visible input tokens2,048 visible input tokens; some models may cache shorter prefixes2,048 visible input tokens; some models may cache shorter prefixes
Cached-token reportingExact eligible boundary, excluding hidden tokensExcludes hidden tokens and rounds down to a multiple of 128Excludes hidden tokens and rounds down to a multiple of 128
Cache read charge0.1× the uncached input-token rateModel-dependent cached-input rateModel-dependent cached-input rate
Cache write charge1.25× the uncached input-token rateNo additional cache-write chargeNo additional cache-write charge
Cache lifetime controlprompt_cache_options.ttlprompt_cache_retentionprompt_cache_retention
Supported retention values"30m""24h" only"in_memory" or "24h"*
Cache lifetimeAt least 30 minutes after the latest write or reuseTypically around 30 minutes, up to 24 hoursTypically 5 to 10 minutes inactive for in_memory, or up to 24 hours for 24h

* Extended retention is supported by gpt-5.5, gpt-5.5-pro, gpt-5.4, gpt-5.2, gpt-5.1-codex-max, gpt-5.1, gpt-5.1-codex, gpt-5.1-codex-mini, gpt-5.1-chat-latest, gpt-5, gpt-5-codex, and gpt-4.1.

How to optimize prompt caching

Focus on preserving conversation history, keeping tool definitions stable, and understanding the three main cache controls. Use prompt_cache_options.mode and prompt_cache_breakpoint to choose where caching occurs, and prompt_cache_key to help related requests reach the same cache.

Ask ChatGPT to optimize my prompt caching

Examples

Gotchas

Frequently asked questions