Response caching
Definition
The response cache stores a successful model response and returns it for a later, identical request without calling the provider. The cache is exact-match: only a byte-for-byte identical request, in the same scope, hits it.
Function
A cache hit saves the cost and latency of the upstream call. It is useful for workloads with repeated identical prompts, for example a classification prompt run over many inputs. It is not useful for conversational traffic, where every request differs.
The cache key
The key is built from:
- the tenant and the gateway,
- the caller's role (a request without a user, such as a gateway-token call, has its own scope),
- a fingerprint of the gateway's full configuration,
- the provider and the model as requested,
- the request body, without the delivery-only fields
streamanduser(field order does not matter), - the request-scoping headers for web search and selected knowledge.
Because the key includes the gateway, two gateways never share entries, even in the same tenant. A gateway that masks personal data can therefore never receive a raw answer cached by another gateway. If the gateway identity is absent, caching is disabled (fail closed).
The cache is consulted before the guardrails run. The role and the configuration fingerprint therefore keep an entry reachable only for callers and settings under which the guardrails would have produced the same outcome. A role that a role policy denies a model never receives an answer cached by another role. Any change to the gateway configuration (guardrails, role policies, model lists, provider settings) makes earlier entries unreachable: at once on the node that served the change, and within the configuration cache TTL on the other nodes. The first request after a change is a miss. The first request after an upgrade that introduced these fields is also a miss.
Rules and facts
- Caching is off until it is enabled per gateway with a time to live (TTL).
- On a hit, the gateway returns the stored response with the
X-AIG-Cache: HITheader, and the request log records the cost and latency saved. - A cache hit spends nothing, so spend caps (trial, user and team budgets) and checks that apply only when the gateway calls a provider do not apply to it.
- Personal keywords are per user and only mask text; the key has no user scope. Two users of the same role on the same gateway who send an identical request can therefore share an entry.
- There is no user-facing bypass header. A spoken-answer turn (
x-aig-voice-lang, set by the gateway's own voice session) is also never cached (see What is not cached): any request carrying a valid value must use a local model, and a malformed value is rejected with400 invalid_voice_lang. Any change to a key field produces a miss. - Semantic caching (matching similar, not identical, prompts) is disabled in the product for data-protection reasons.
What is not cached
A request is neither read from nor written to the cache when its answer depends on who asks, on live data, or on scope that the key cannot express. This includes:
- streaming requests and non-200 responses,
- requests from the
demouserrole (the demo quota counts every prompt, which a hit would skip), and requests whose role or gateway configuration is missing or malformed, - requests that name a conversation, or act within a project, or whose project binding cannot be confirmed,
- requests with a duplicated single-value scoping header, or with a knowledge exclusion list,
- agent invokes, requests that carry MCP tools, and turns that run a live web search,
- regenerate requests and Copilot document-AI actions,
- spoken (voice) turns: requests carrying the gateway-internal
x-aig-voice-langheader (the voice session's own loopback call).
A turn the client cut, or whose provider leg failed, is also never written to the cache, even with status 200: a partial answer is never served to a later request.
See also
- Configuration reference —
cache_ttland the (disabled) semantic-cache settings. - Gateways — where caching is enabled.
- Request pipeline — where the cache check and store run.
- Cost attribution — the saved cost recorded on a hit.