Prompt caching | OpenAI API
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 and use the Prompt Cache Diagnostics tool to diagnose cache misses and improve cache reuse.

What is the prompt cache?

When the model processes input tokens, it must calculate intermediate states, known as key-value (KV) states. These states let the model refer back to earlier tokens while processing new input and generating output tokens.

Prompt caching preserves that state for a reusable prefix: the unchanged tokens at the beginning of a prompt. 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 subsequent requests look for the longest matching cached prefix available, working backward through eligible breakpoints until they find 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 varies by request settings for earlier models. See the model comparison for details.

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.

How prefix matching works

OpenAI walks through only the cache lookup boundaries (explained below) in the incoming request, from longest prefix to shortest, looking for an available matching prefix already cached on the machine.

For GPT-5.6 and later, the cache lookup boundaries in the incoming request are:

  • Explicit-only mode: The first 2 and latest 50 explicit breakpoints.
  • Implicit mode: The first 2 and latest 50 explicit breakpoints, the implicit breakpoint, up to 20 earlier eligible message endings, and the endpoint of the initial consecutive block of developer messages. This lets implicit mode reuse a prefix ending at an earlier message without explicit breakpoints there.
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.
  • An optional prompt_cache_key, which separates cache reuse between groups of requests.

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 message.Spaced at regular 2,048-token intervals.Spaced at regular, model-dependent intervals.
Explicit breakpointsSupportedNot supportedNot supported
Minimum cacheable prefix1,024 visible input tokensVaries by request settingsVaries by request settings
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.

For models before GPT-5.6, the minimum cacheable input length varies with request settings, including tools, images, output schemas, reasoning effort, and verbosity.

How to optimize prompt caching

Focus on preserving conversation history, keeping tool definitions stable, and choosing where caching occurs. Use prompt_cache_options.mode and prompt_cache_breakpoint to control cache breakpoints. If your application needs separate cache accounting for customers, you can also use an optional prompt_cache_key.

Ask ChatGPT to optimize my prompt caching

Examples

Gotchas

Frequently asked questions