Uh oh!
There was an error while loading. Please reload this page.
fix(opencode): set 1h prompt cache TTL for OpenRouter - #16850
Conversation
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
rekram1-node
commented
Mar 10, 2026
Do they document this? |
732d370 to
2d2a432Comparerndmcnlly
commented
Mar 11, 2026
Good question -- it caught a real bug. Yes, they document it: https://openrouter.ai/docs/guides/best-practices/prompt-caching Key quote from the Anthropic section:
The documented mechanism is I ran a 3-way empirical test with a 6-minute delay past the 5-min default TTL: Only the documented Verification script (~7 min, needs Sorry for the original mistake -- my local test only checked that the parameter was accepted without error, not that it actually extended the TTL. |
…trol
Use the documented cache_control { type: "ephemeral", ttl: "1h" } on
message content for OpenRouter. The default 5-minute TTL causes constant
cache misses and rewrites during normal usage gaps (reviewing output,
editing files, thinking). Extending to 1 hour significantly reduces
redundant cache write costs on Anthropic models via OpenRouter.
Empirically verified: only the per-message cache_control.ttl approach
survives past 5 minutes; the undocumented top-level prompt_cache_ttl
parameter is silently ignored.
Closesanomalyco#168482d2a432 to
40e83a5CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
rndmcnlly
commented
Jun 1, 2026
Re-opened as #30190 (this PR was auto-closed by the stale bot). |
Issue for this PR
Closes#16848
Type of change
What does this PR do?
Adds
prompt_cache_ttl: 3600alongside the existingprompt_cache_keyfor OpenRouter, extending cache lifetime from 5 minutes to 1 hour. Without it, any idle gap over 5 min between prompts triggers a full cache miss and rewrite.Tested with curl against OpenRouter -- parameter is accepted for both Anthropic and non-Anthropic models. Non-Anthropic models silently ignore it. Anthropic models show cache hits (
cached_tokens > 0) on follow-up requests.How did you verify your code works?
bun test test/provider/transform.test.ts-- 108 tests pass including the new oneprompt_cache_key+prompt_cache_ttl: 3600onanthropic/claude-sonnet-4-- confirmed cache write on first request, cache hit on secondgoogle/gemini-2.5-flashwith same params -- 200 OK, param silently ignoredScreenshots / recordings
N/A -- no UI change.
Checklist