Which requests qualify?
This table describes channel affinity. GPT models can also use prompt caching through Chat Completions, as shown below.
Requests that do not meet these conditions follow the usual routing rules.
Request examples
SetMIXROUTE_API_KEY before running these examples. Use a model available to the group associated with your API key.
Example 1: Codex / GPT (/v1/responses)
MixRoute identifies the session using prompt_cache_key in the body. Keep the same value for every request within the session.
prompt_cache_key unchanged and append the new content to input:
Example 2: GPT (/v1/chat/completions)
Put fixed instructions or reference material at the start of messages and put the question that changes each turn at the end. Keep the prefix unchanged on later requests. prompt_cache_key is an optional cache grouping key. If you use it, keep it the same for requests in the group that share a prefix.
usage.prompt_tokens_details.cached_tokens is greater than 0.
Example 3: Claude (/v1/messages)
MixRoute identifies the session using metadata.user_id in the body. Keep it unchanged within the session.
Affinity helps send requests to the same channel. It does not create the upstream cache. Claude supports cache_control under its upstream cache rules, and the example adds an explicit cache marker.
Example 4: Gemini (native and OpenAI-compatible APIs)
Both APIs use theX-Session-Id request header to identify the session. Reuse the same value for each request in that session. Choose either API format below.
Gemini native API
/v1/chat/completions)
Python example (official OpenAI SDK)
Python example (official Anthropic SDK)
How to check for cache hits
Inspect the usage fields in the response:- Responses:
usage.input_tokens_details.cached_tokensgreater than 0 indicates a cache hit. - Messages:
usage.cache_read_input_tokensgreater than 0 indicates a cache hit. - Chat Completions: When the response includes
usage.prompt_tokens_details.cached_tokens, a value greater than 0 indicates a cache hit. - Gemini native API:
usageMetadata.cachedContentTokenCountgreater than 0 indicates a cache hit.
Common mistakes
FAQ
Q1: Why do my requests keep going to the same channel? Once MixRoute selects a channel, subsequent requests with the same session identifier will try to reuse it. A new session may go to another channel. Q2: Do different groups or rules share a binding? By default, session bindings are separate across groups and routing rules. Q3: Why does a channel error not cause a retry on a different channel? By default, if the bound channel fails, MixRoute returns the error rather than automatically switching channels. A new channel may not be able to reuse the original cache.- Retry shortly afterward in case the upstream problem is temporary.
- If the error persists, start a new session. A new identifier causes MixRoute to select a channel again.
- If the problem continues, contact support with the time and request ID.
- The session identifier changes between requests, so MixRoute cannot recognize the same session and keep the channel stable.
- The prompt prefix changes between requests, such as when a timestamp is inserted at the start.
- A new session does not yet have any cached content.
- The channel binding may have expired after a long pause.
Summary
- Affinity covers eligible GPT Responses, Claude Messages, native Gemini, and Gemini on Chat Completions requests.
- Keeping a session on the same channel helps it reuse prompt caches.
- MixRoute does not switch channels automatically after a bound-channel error by default. Retry shortly afterward or start a new session.
- When writing your own script, keep the session identifier stable.