fix(opencode): set 1h prompt cache TTL for OpenRouter#16850
fix(opencode): set 1h prompt cache TTL for OpenRouter#16850rndmcnlly wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Do they document this? |
…ed prompt_cache_ttl
prompt_cache_ttl is silently ignored by OpenRouter. The documented approach
is cache_control: { type: "ephemeral", ttl: "1h" } on message content,
which empirically survives a 6-minute idle gap.
732d370 to
2d2a432
Compare
|
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. |
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