You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.
Without a longer TTL, 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. The 5-minute default ends up costing more overall because the cache is constantly being rewritten.
Caution
The fix originally sketched below is broken. The top-level prompt_cache_ttl parameter is silently ignored by OpenRouter — no error, no cache write, nothing. See the conclusive empirical research in #16850, including a 3-way verification script that tested with a 6-minute delay past the default TTL.
The fix is one line next to the existing prompt_cache_key assignment:
// BROKEN — silently ignored by OpenRouterif(input.model.providerID==="openrouter"){result["prompt_cache_key"]=input.sessionIDresult["prompt_cache_ttl"]=3600// does nothing}
The correct documented mechanism is cache_control: { type: "ephemeral", ttl: "1h" } on message content (OpenRouter docs). This is a one-line change in the existing applyCaching function. The fix is implemented and tested in #16850.
[FEATURE]: Set
prompt_cache_ttlfor OpenRouter providerFeature 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_keyfor OpenRouter inProviderTransform.options()(packages/opencode/src/provider/transform.ts, line 790), but we don't set a TTL. OpenRouter defaults to 5 minutes.Without a longer TTL, 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. The 5-minute default ends up costing more overall because the cache is constantly being rewritten.
Caution
The fix originally sketched below is broken. The top-level
prompt_cache_ttlparameter is silently ignored by OpenRouter — no error, no cache write, nothing. See the conclusive empirical research in #16850, including a 3-way verification script that tested with a 6-minute delay past the default TTL.The fix is one line next to the existingprompt_cache_keyassignment:The correct documented mechanism is
cache_control: { type: "ephemeral", ttl: "1h" }on message content (OpenRouter docs). This is a one-line change in the existingapplyCachingfunction. The fix is implemented and tested in #16850.