anomalyco / anomalyco/opencode

Bug: Anthropic prompt caching not applied when using custom provider name with Anthropic protocol via proxy

Open
#45,750 7 comments 0 reactions 1 assignee View on GitHub

@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

  1. 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 } }
      }
    }
  }
}
  1. Put a long static document (e.g. 20k+ chars) in instructions so it is injected as system prompt every turn.
  2. Chat for several turns within a few minutes (well under the 5-minute ephemeral TTL).
  3. 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)

  1. Proxy is fine: calling the proxy directly with anthropic SDK and explicit cache_control: {type: "ephemeral"} on the system block works perfectly — 1st call cache_creation_input_tokens: 1081, 2nd call 3 seconds later cache_read_input_tokens: 1081 (100% hit).
  2. Not a TTL issue: rapid-fire messages within 5 minutes still produce 0 hits via opencode.
  3. setCacheKey: true (the OpenAI-protocol fix from issue #17610) does not help for the Anthropic protocol.
  4. 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
  1. 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 } }
      }
    }
  }
}
  1. Put a long static document (e.g. 20k+ chars) in instructions so it is injected as system prompt every turn.
  2. Chat for several turns within a few minutes (well under the 5-minute ephemeral TTL).
  3. Check proxy-side usage stats.
Screenshot and/or share link
Image
Operating System

Windows 11

Terminal

OpenCode Desktop

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.