anomalyco / anomalyco/opencode
[FEATURE]: Enable OpenAI prompt caching by setting `prompt_cache_key` for GPT-5.6+
@jlongster is already working on this.
Since Aug 20, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Problem
OpenAI GPT-5.6+ supports prompt caching, but it requires setting prompt_cache_key in API requests for reliable cache matching. Without this, users pay full input token costs on every message, even in long sessions where the context is largely unchanged.
Real-world impact: In a 1 hour window of a 32-hour session using GPT-5.6, I spent ~$700. The session data shows cache_read: null and cache_write: null for all OpenAI messages, meaning zero caching occurred. Switching to Claude mid-session immediately showed cache hits (173M tokens read from cache) because Anthropic's caching works automatically.
OpenAI's Caching Requirements
From OpenAI's docs:
For GPT-5.6, you must set
prompt_cache_keyto use the more reliable matching for both implicit and explicit caching. At each breakpoint, the service matches the key with the exact prompt prefix. Without a key, requests may still receive automatic cache hits, but they do not use the improved matching.
Key parameters:
prompt_cache_key: String identifier (e.g., session ID) - required for reliable cachingprompt_cache_options.mode:"implicit"(default) or"explicit"prompt_cache_options.ttl: Cache lifetime (default"30m")
Current State
OpenCode already:
- ✅ Tracks cache tokens from OpenAI responses (
cached_tokens,cache_write_tokens) - ✅ Has a
cacheKeyoption in the provider interface - ❌ Does NOT pass
prompt_cache_keyto OpenAI API requests
Proposed Solution
Set prompt_cache_key to the session ID for OpenAI GPT-5.6+ requests:
{
"model": "gpt-5.6",
"prompt_cache_key": "ses_abc123...",
"messages": [...]
}
This would:
- Enable reliable prompt caching for long sessions
- Dramatically reduce costs (cached tokens are billed at 0.1× the uncached rate)
- Reduce latency for repeated context
Configuration Options
Could be exposed as a provider-level or global config option:
{
"provider": {
"openai": {
"promptCache": true // or "auto" | "off"
}
}
}
Or enabled by default for supported models (GPT-5.6+).
Workaround
Currently none. The opencode-cache-injector plugin exists but only works for Claude API proxies, not native OpenAI.
Environment
- OpenCode version: latest
- Models affected: GPT-5.6, GPT-5.5, GPT-5.4, GPT-5.2, GPT-5.1, GPT-5, GPT-4.1 (all models supporting
prompt_cache_key)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.