Use It In Your Policy
UsecreateDariRoutingPolicy, not a plain inline RoutingPolicy:
cacheState.read() returns the state the policy engine needs:
What You Get
For a conversation with a warm incumbent, the policy engine compares each switch’s cold-prefix cost with its expected savings. It automatically removes a switch unless it saves at least 10% on the fixed-turn cost. So whengpt-5.4-mini looks a little cheaper but switching would reprocess a large warm prefix, it is removed before the selector chooses. A genuinely cheaper switch stays available.
This protection works only when all of these are true:
- The request has a stable
prompt_cache_key. - Your saved state identifies the previous model and a still-warm prefix.
- You provide normal and cached-input prices plus observed output-token averages for each model/effort.
Send The Same Key Every Turn
Sendprompt_cache_key on every request in one conversation:
request.cacheKey; createPiRuntime() passes it to Pi as the provider session ID. Custom executors receive request.cacheKey and should map it to the cache or session field supported by their provider.
Provider cache hits remain the provider’s decision. Executors return observed usage as cacheReadTokens and cacheWriteTokens; the protocol adapters serialize those values in the caller’s native usage format.
Leases Are A Simpler Fallback
A lease keeps later turns on one model, but it is not a cache-cost calculation or a cache hit. UseleaseTurnsRemaining when you only want short-term stickiness. Use cache-aware routing when you persist prefix observations and want the policy to decide whether a switch is actually worth it.
Read Policies for the full policy setup and Decision Pipeline if you need to control persistence and selection phases yourself.