How the exact cache works
The gateway stores a model’s complete reply and replays it when the same caller sends the exact same request again before the reply expires. Exact means every part of the request matches: messages, tools, sampling settings, output constraints, and whether it streams.
What is cached:
- Complete chat replies, unary and streamed, and embedding replies.
- A streamed reply only when the stream finished normally with its usage known, and stayed under 2 MiB.
- Not decisions, images, audio, or any other modality.
Before you begin
- You’re an organization admin, to turn the cache on for a model.
- The model’s modality is
chatorembedding. Settings offers the cache only for those.
1
Open the model's settings
In Model Gateway studio, open Models, select the model, and open its Settings tab.
2
Turn on the exact-answer cache
Under Exact-answer cache, switch from Off (default) to On. In Keep an identical answer for, enter how long to keep a reply, from 1 to 3,600 seconds.
3
Save the model
Select Save changes.
Control the cache per request
Callers can narrow the cache for one request with headers. The model’s setting is always the upper bound: a caller can shorten the time a reply is kept, never lengthen it. These headers are never forwarded to the provider.x-gateway-cache other than bypass or no-store returns 400 with x-gateway-cache must be bypass or no-store. A x-gateway-cache-ttl that isn’t a whole number of seconds returns 400 with invalid x-gateway-cache-ttl.
Verify
- On the model’s Overview tab, Routing and health reads
Exact-answer cache on, 60 s.for a 60-second setting. - Send the same chat request twice, with the same key.
- A fresh reply has an
x-gateway-model-wireheader naming the provider API that answered. A reply served from the cache has nox-gateway-model-wireheader, because no provider API was called.
Exact cache versus provider prompt caching
Providers such as Anthropic cache the start of a long prompt and bill those tokens at a lower rate. That is a separate feature, and the gateway keeps it separate.
The gateway forwards
cache_control markers to providers whose API reads them: the Anthropic Messages API (direct, on Vertex AI, or on Azure AI Foundry), Amazon Bedrock, OpenRouter, and a LiteLLM proxy. On Bedrock only {"type": "ephemeral"} is carried. Other provider APIs have no such marker, so the gateway drops it there.
Related
- How Model Gateway works: what the gateway keeps and doesn’t.
- Model API compatibility: every request and response header.
- Review model usage: find cached input on a call.