The cache is switched on for a whole deployment by its operator, then a team or a workspace opts in. If
X-ManyLayers-Cache on your responses always says disabled, one of those switches is off — see Eligibility.How it works
The cache has two layers that are checked in order:- Exact match. A SHA-256 key built from the redacted request. A hit returns the stored completion immediately.
- Semantic match (optional). On an exact miss, the prompt is embedded and compared with earlier prompts in the same scope (team, workspace and optional namespace) for the same model. A close enough neighbour is returned. A request that uses tools (
tools,tool_choiceor tool turns) never reads or writes the semantic layer. A semantic hit carriesX-ManyLayers-Cache-Similarity(four decimals).
id starting cache-, a single assistant message, the stored finish_reason (stop, or tool_calls when the entry has tool calls) and the stored tool_calls; a streamed request is replayed as a stream. A reply is not stored if a tool call lacks an id or name, has invalid-JSON arguments, or comes from Gemini or Vertex.
Eligibility
A request uses the cache only when all of these hold:cache.enabled: truefor the deployment.- The cache is switched on for the request: the calling team has
cache_enabled: true, or the request’s workspace has the cache switched on (Settings → Cache, orPUT /admin/gateway/cache-configwith{"workspace_cache_enabled": true}, which needsgateway.workspaces.manage), or a caller holdinggateway.workspaces.manageopts that request in withX-ManyLayers-Cache-Type. A virtual account has no team, so only the workspace switch or the opt-in applies to it. The semantic layer can also be switched on by the workspace’s own semantic-cache settings (PUT /admin/gateway/semantic-cache) without the exact-match switch. - The endpoint is
/v1/chat/completions,/v1/completions,/v1/responsesor/v1/messages. Embeddings are never cached. - The request sets
temperatureto exactly0, or the model is configured withcache: true.
X-ManyLayers-Cache: disabled, and X-ManyLayers-Cache-Reason says why: no_backend (cache off for the deployment), not_enabled (no team, workspace or opt-in switch), embeddings or not_deterministic (no temperature: 0 and no model cache: true).
The model-level
cache: true flag is a gateway.yaml model setting. Models registered through Gateway → Providers do not carry it, so for them only requests with "temperature": 0 are cached.cache_enabled on POST /admin/teams (organization Owner; see Keys & Budgets), or switch the cache on for a whole workspace as described above.
Exact key composition
The exact key hashes:- the entry’s scope: team, workspace and optional namespace;
- the resolved logical model name;
- the text of every message (after redaction), then
prompt, theninput; - these parameters, when present:
temperature,top_p,max_tokens,n,stop,tools,tool_choice,parallel_tool_calls,response_format; - for a request with tool turns, each tool or call message’s position, role,
tool_call_idand call text.
stream is not part of the key, so a streamed and a non-streamed request share one entry; a streamed request is replayed as a stream.
Configuration
Deployment-wide settings, fromgateway.yaml or the administration console under Settings → Cache. Each workspace can also switch the exact cache on (GET/PUT /admin/gateway/cache-config, {"workspace_cache_enabled": bool}) and configure its own semantic cache (GET/PUT /admin/gateway/semantic-cache, {enabled, embedding_model, threshold}; errors unknown_embedding_model and invalid_threshold). The deployment’s cache.enabled must still be on.
gateway.yaml (fragment)
Key fields
A model the gateway calls on itself, as the calling identity, to embed prompts. It must be in the requesting team’s allowed models; if the embedding call fails for any reason, the request is treated as a plain miss.
memory keeps a per-replica LRU. qdrant shares entries across replicas in the ml_semantic_cache collection and requires rag.qdrant.url.Backends
Redis errors are treated as cache misses, never as request failures. Backend changes take effect after a restart.
Per-request control
no-cache skips the lookup; no-store skips writing the answer. Combine them as no-cache, no-store. Any other value is a 400. The header can only make the gateway cache less — it never makes an ineligible request cacheable — and it is removed before the request is forwarded.exact or semantic: use only that layer. semantic answers 400 semantic_cache_unavailable if the semantic layer is not on. From a caller holding gateway.workspaces.manage (or an operator) it also opts the request in when no team or workspace switch is on.1–128 characters of letters, digits and
. _ : -. Partitions the team’s cache: entries written under one namespace are never served to another.400 invalid_header. All are removed before the request is forwarded.
Kept even when a routing config sets
strict_openai_compliance, which otherwise strips the other X-ManyLayers-* response headers.Monitoring
GET /admin/cache/stats aggregates lookups since ?since= (RFC 3339, default the last 24 hours). It is a deployment-operator endpoint: it needs an admin-role credential and is not available to workspace roles, so on the hosted service ask ManyLayers or use the Prometheus metric below.
latency_saved_ms sums the original generation time of each entry that was served.
Bypassed and ineligible requests are not counted.
Next steps
PII Detection & Redaction
Redaction runs before the cache key is built.
Metrics
Chart hit rate alongside latency and spend.
Self-Host the Gateway
Add Redis to share the exact cache across replicas.
Routing
What happens on a cache miss.