Overview
GoModel ships with two response-cache layers for streaming and non-streaming requests on:/v1/chat/completions/v1/responses/v1/messages/v1/embeddings/v1/systemone(and Kev’s/permuteand/separate)
text/event-stream. A stream longer than 4 MiB still
reaches the client in full but is not cached.
Exact-match cache returns byte-identical responses with:
/v1/embeddings participates in the exact cache only. An embedding has to
represent the exact text it was requested for, so replaying the vector of a
merely similar input would be a wrong answer rather than an equivalent one.
Embeddings requests are also never streamed, so only the JSON response is
cached. The same holds for System One
decisions: a similar state is not the same decision.Enable the exact cache
Point response caching at Redis:REDIS_URLREDIS_KEY_RESPONSESREDIS_TTL_RESPONSES
Enable semantic caching
Add asemantic block with an embedder provider and a vector store:
qdrantpgvectorpineconeweaviate
Cache-Control: no-cache or
Cache-Control: no-store to bypass caching per request. A
plugin can also keep one response out of both
layers with NoStore on its decision, which a guardrail that restores
request-specific data into the reply uses so the restored text is never
replayed to another caller. A background: true request on
/v1/responses bypasses both
layers as well: its queued body carries an id that belongs to one caller’s
response.
For the full semantic-cache design and storage options, see
ADR-0006.
What the exact cache keys on
The exact cache hashes:- the request path
- the resolved workflow context used for execution specifically execution mode, provider type, and resolved model
- the guardrail chain the request resolves to, across the prompt, response and stream phases
- the final request body
- the effective
user_path, only whenpartition_by_user_pathis on (see below)
What the semantic cache keys on
A semantic hit needs a similar last user message and an identical match on everything else:- the request path, resolved provider and model, guardrail chain, and embedder
- the earlier conversation turns, plus any non-text parts of the last user message
- every other top-level request field, such as
temperature,seed,stop,n,tools,tool_choice,response_format,text,reasoning_effort,thinkingorsystem, and any field GoModel does not recognize - whether the request streams;
stream_optionsonly counts whenstreamistrue
user,
metadata, safety_identifier, prompt_cache_key and
prompt_cache_retention. On /v1/responses they count, because the response
echoes them back to the caller. With exclude_system_prompt: true, system
messages and a top-level system are left out as well; Responses
instructions always count.
Provider prompt-cache planning
After routing resolves the concrete provider and model, GoModel adds a cache plan when the stable prefix meets that provider’s minimum size and the client did not already supply a cache directive:- OpenAI receives a stable
prompt_cache_key; models supporting explicit caching also receive a breakpoint and explicit cache mode. - Anthropic receives top-level automatic ephemeral caching.
- Amazon Bedrock Converse receives a cache point after the stable prefix.
- Native Gemini AI Studio creates and reuses a five-minute cached-content object, with concurrent creation coalesced by prefix and stable credential.
true) and an invalid value emits a startup warning.
user_path behavior
By default, user_path is not part of the cache key in either layer.
That is intentional. If two requests end up with the same path, resolved
workflow, and final request body, they can share the same entry even when they
originate from different user_path values, and so can similar prompts in the
semantic cache. Sharing gives the best hit rate, and it also means one tenant
can be served a response cached for another.
Partition the cache by user_path
Enable partitioning when callers must not receive each other’s cached
responses, for example when API keys bound to a user_path belong to different
tenants:
RESPONSE_CACHE_PARTITION_BY_USER_PATH=true.
The setting covers every cache layer each endpoint above uses (embeddings and
System One use only the exact cache), streaming or not:
- Requests with different effective
user_pathvalues never share an entry. In the exact cache, concurrent identical misses only wait for a request from their own path. - Paths match exactly.
/team/alphadoes not reuse entries from/teamor/team/alpha/bob. - Requests with no
user_pathform their own partition, separate from/. - Each path pays for its own first request, so hit rates drop when tenants send the same prompts.
ttl: 0 never expire, so clear those.
Other ways to scope the cache
If you only need different cache behavior per scope, not isolation:- disable cache in a scoped workflow
- use different scoped workflows for different
user_pathvalues - include scope-specific context so the final request body differs
Responses served through failover are not cached
When a request is answered by a failover target rather than the one routing picked first, the response is not stored. The exact-cache key is hashed from the pre-failover resolution, so storing the backup’s answer would serve it under the primary’s key once the primary recovers. The practical consequence: a virtual model whose first target is chronically down stops accumulating cache entries for as long as it stays down — every request that misses fails over and is served fresh, and nothing it produces is stored. Entries written before the outage keep serving until their TTL expires: a lookup runs ahead of dispatch, so a hit is returned without touching either target. If a target is going to be unavailable for a while, reorder the chain (or point the virtual model at a healthy target) so the responses that answer it are cacheable again. Retries within one target are unaffected: only a response produced after the sweep moved to another target is withheld from both cache layers.Cache analytics
When response caching and usage tracking are enabled, the admin API exposes a cached-only overview at:user_path
and a cache_type of exact or semantic. The usage endpoints
(/admin/usage/* and /v1/usage) leave them out by default so that totals and
cost track provider spend; pass cache_mode=all to include them, or
cache_mode=cached to see only the hits. /admin/usage/sessions is the
exception: session request and token totals always include cache hits, while
its cost fields stay provider-only.