-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Description
[FEATURE]: Set prompt_cache_ttl for OpenRouter provider
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
(Note: #5416 and #5422 cover broader caching config. This is about one missing parameter on an existing code path.)
Describe the enhancement you want to request
We already set prompt_cache_key for OpenRouter in ProviderTransform.options() (packages/opencode/src/provider/transform.ts, line 790), but we don't set a TTL. OpenRouter defaults to 5 minutes.
OpenRouter supports a prompt_cache_ttl parameter alongside the key (docs). Without it, any idle gap over 5 minutes between prompts triggers a full cache miss and rewrite on the next turn. For Anthropic models this is common in real usage — reviewing output, editing files, thinking, etc.
Setting prompt_cache_ttl to 3600 (1 hour) trades a higher write cost (2x vs 1.25x) for far fewer write-miss-write cycles. In sessions with any idle gaps, the 5-minute TTL ends up costing more overall because the cache is constantly being rewritten.
The fix is one line next to the existing prompt_cache_key assignment:
if (input.model.providerID === "openrouter") {
result["prompt_cache_key"] = input.sessionID
result["prompt_cache_ttl"] = 3600 // 1 hour; default is 5 minutes
}Happy to put up a PR with a test if this direction looks right.