Prompt cache keys: design reusable prefixes and user separation
A prompt cache key is an identifier an API provider may use to route or account for cache processing across repeated requests. **The key does not store prompt text or guarantee a cache hit when the content differs.** Cache reuse primarily depends on an eligible, identical prefix in the model request; a key's role varies by provider and model version. An application-owned hash of prompt text is also a different concept from an API cache key.
A prompt cache key is an identifier an API provider may use to route or account for cache processing across repeated requests. The key does not store prompt text or guarantee a cache hit when the content differs. Cache reuse primarily depends on an eligible, identical prefix in the model request; a key's role varies by provider and model version. An application-owned hash of prompt text is also a different concept from an API cache key.
How are a cache key and a cache hit different?
When a request has a long input prefix that repeats, a provider may reuse previously computed prefix state. A later request must arrive with the same eligible prefix and compatible settings to be a reuse candidate. Prompt caching generally uses an exact, contiguous prefix from the start of the request. Changing an instruction, tool definition, schema, or prior conversation partway through can reduce or end reuse after that point.
An API field such as prompt_cache_key is metadata a provider may use to help route cache lookups or separate usage accounting by user or customer. OpenAI's documentation checked on 2026-11-23 describes behavior that depends on model generation. On models before GPT-5.6, a stable key for requests with the same reusable prefix can help cache routing. On GPT-5.6 and later, the key is not needed to optimize cache hits; its documented focus is separate cache usage accounting by customer/user/workspace and reducing cache-hit probing across users. Check the current API documentation for the model you use.
So the same key does not guarantee a hit when the prefix changes, and a provider may reuse an identical prefix without a key. Check whether the response reports cached input tokens and what the API diagnostics say. Changing the key on every request can disrupt routing or accounting for related requests. Conversely, if all customers share one key, their usage accounting may be combined.
How does this differ from an application prompt hash?
An application-computed content hash can detect changes in specified normalized text or configuration and support logs, versioning, or deduplication. Its value depends on the application's chosen input and normalization. A provider's prompt_cache_key is an API input for its caching feature; it is not automatically a cryptographic hash of the text or a prompt version.
| Purpose | Suitable identifier | Considerations |
|---|---|---|
| Cache routing or per-user cache accounting | Provider API cache key | Meaning and need vary by model. Reuse it consistently within the same cache scope. |
| Detecting prompt changes and audit | Application version ID or content hash | Decide whether to include message order, tool schemas, and settings needed to reproduce behavior. You need not log sensitive source text. |
| Confirming a cache hit | Response usage fields and provider diagnostics | Do not infer a hit from the key value. Check actual cached read/write tokens or diagnostic output. |
If you only want to check whether each request has an identical prefix, do not automatically send the application content hash as the cache key. If the prompt changes per request, the hash changes too and can scatter cache routing. If you need customer separation, use a stable, non-secret internal customer identifier as permitted by provider policy, rather than a content hash. Do not put account numbers, email addresses, full prompts, or other sensitive values in the key.
How do you build a reusable prefix?
**Find what repeats.** Keep fixed roles and service rules, tool definitions, and shared reference material identical across requests.
**Put variable content later.** Place user-specific questions, current timestamps, and newly retrieved documents after the common prefix. If the model/API supports cache breakpoints, put a breakpoint after a stable reusable section.
**Keep compatibility conditions stable.** Changes to model, tool names/order/descriptions/schema, or service tier can affect reuse. Check the model documentation to learn which conditions participate in cache matching.
**Keep the key policy simple.** Decide whether per-user accounting or routing optimization on older models is actually needed. If so, reuse a stable key within the cache scope; otherwise omit it.
**Verify with response data.** Check cached read/write tokens, total input tokens, latency, and cost on first and later requests. A cache setting or key value alone is not proof of success.
For example, a customer-support application might keep shared policy and tool schemas at the beginning, then append the current retrieved case materials later. If usage must be separated by customer, it could use a stable internal customer key after checking organizational rules and provider support. Reuse still requires the common prefix and cache/model conditions to match. This is a design example, not a tested API request.
When hits fail or usage is mixed
**Cache usage fell after changing the key:** Check whether each request has a unique ID or changing hash. If you do not need group separation, use a stable key or omit the field.
**The key is the same, but there are no hits:** Compare the fully rendered prefixes. A timestamp, conversation summary, tool schema order, whitespace/message boundary, model, or service setting may have changed.
**You cannot tell whether the response read from cache:** Do not treat the key as evidence. Check cached-token usage fields or provider diagnostics, interpreting fields according to the API and model version.
**Usage accounting is mixed across customers:** Check whether key scope matches your separation goal. If isolation is a security or privacy requirement, do not assume the key is the security boundary; review the provider's isolation and storage policies.
**Costs increased:** Consider cache-write cost, lifetime, prefix length, and actual reuse frequency together. Short or rarely reused prompts do not necessarily benefit from caching.
Cache lifetime, minimum prefix length, explicit breakpoints, pricing, and setting names vary by model and API version. Verify the official documentation and usage response at deployment time. If caching is required for performance, monitor cache-read tokens and latency and design fallback behavior.
Sources
[OpenAI API: Prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) — Prefix reuse, model-dependent `prompt_cache_key` roles, stable prefixes, and cache measurement. Checked 2026-11-23.
[OpenAI API: Prompt cache diagnostics](https://developers.openai.com/api/docs/guides/prompt-caching/diagnostics) — Diagnosing why expected cache reuse does not occur because model, tools, key, or service conditions differ. Checked 2026-11-23.
[OpenAI API: Keep the prefix unchanged](https://developers.openai.com/api/docs/guides/keep-prefix-unchanged) — Relationship between prefix changes and reuse in conversational requests. Checked 2026-11-23.