anomalyco / anomalyco/opencode
Bug: Anthropic prompt caching not applied when using custom provider name with Anthropic protocol via proxy
@jlongster is already working on this.
Since Aug 27, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
When using Claude models through a third-party proxy (e.g. OfoxAI) via the Anthropic native protocol, prompt caching never activates — cache hit rate stays at 0%, even with rapid consecutive messages.
The root cause appears to be related to PR #1305: Anthropic handles content-level caching "natively", but that native caching logic seems to only apply when the provider is the built-in anthropic provider. A custom provider (e.g. ofox_ai) using npm: "@ai-sdk/anthropic" does not receive automatic cache_control marks.
Environment
- opencode version: latest (1.x, upgraded on 2026-08-28)
- OS: Windows 11
- Proxy: OfoxAI (https://api.ofox.ai)
- Protocol: Anthropic native (
baseURL: https://api.ofox.ai/anthropic) - Model:
anthropic/claude-sonnet-4.5
Steps to reproduce
- Configure a custom provider with
"npm": "@ai-sdk/anthropic"pointing at an Anthropic-protocol proxy:
{
"provider": {
"ofox_ai": {
"npm": "@ai-sdk/anthropic",
"options": { "baseURL": "https://api.ofox.ai/anthropic" },
"models": {
"anthropic/claude-sonnet-4.5": { "limit": { "context": 1000000 } }
}
}
}
}
- Put a long static document (e.g. 20k+ chars) in
instructionsso it is injected as system prompt every turn. - Chat for several turns within a few minutes (well under the 5-minute ephemeral TTL).
- Check proxy-side usage stats.
Expected behavior
Anthropic's prompt caching should kick in: first request creates the cache (cache_creation_input_tokens), subsequent requests hit it (cache_read_input_tokens > 0).
Actual behavior
Cache creation and cache read stay at 0 forever.
Diagnostic evidence (we did the homework)
- Proxy is fine: calling the proxy directly with
anthropicSDK and explicitcache_control: {type: "ephemeral"}on the system block works perfectly — 1st callcache_creation_input_tokens: 1081, 2nd call 3 seconds latercache_read_input_tokens: 1081(100% hit). - Not a TTL issue: rapid-fire messages within 5 minutes still produce 0 hits via opencode.
setCacheKey: true(the OpenAI-protocol fix from issue #17610) does not help for the Anthropic protocol.- Built-in provider name test: renaming the provider to the built-in
anthropic(with custom baseURL) was also tried — still 0 hits in our environment.
Hypothesis
Per PR #1305: "Anthropic handles content-level caching natively, others need explicit control". The native Anthropic caching path may be tied to the built-in anthropic provider's internal adapter, and custom providers (even with @ai-sdk/anthropic) may not get cache marks applied — or the marks are applied in a way proxies don't forward.
Would be great if custom Anthropic-protocol providers could also get native caching, or if there were a documented way to enable it.
Thanks! 🐙
Reported by @utadamaaya (Utada & DeepSeek)
PS:This issue was written by my Deepseek, I was just helping to submit it.
Plugins
No response
OpenCode version
v1.18.23
Steps to reproduce
- Configure a custom provider with
"npm": "@ai-sdk/anthropic"pointing at an Anthropic-protocol proxy:
{
"provider": {
"ofox_ai": {
"npm": "@ai-sdk/anthropic",
"options": { "baseURL": "https://api.ofox.ai/anthropic" },
"models": {
"anthropic/claude-sonnet-4.5": { "limit": { "context": 1000000 } }
}
}
}
}
- Put a long static document (e.g. 20k+ chars) in
instructionsso it is injected as system prompt every turn. - Chat for several turns within a few minutes (well under the 5-minute ephemeral TTL).
- Check proxy-side usage stats.
Screenshot and/or share link
Operating System
Windows 11
Terminal
OpenCode Desktop
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.