一键导入
opencode-detect-openai-compat
OpenCode's caching detection misses OpenAI-compatible proxies routing to Anthropic/Bedrock. Broaden the predicate.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
OpenCode's caching detection misses OpenAI-compatible proxies routing to Anthropic/Bedrock. Broaden the predicate.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | opencode-detect-openai-compat |
| description | OpenCode's caching detection misses OpenAI-compatible proxies routing to Anthropic/Bedrock. Broaden the predicate. |
| target_harness | OpenCode |
| target_repo | sst/opencode |
| target_files | ["packages/opencode/src/provider/transform.ts"] |
| target_commit | dev branch @ a9ef5a0f |
| estimated_savings | 0 → ~90% hit rate for users on LiteLLM/Bifrost/MiMo routing to Claude |
packages/opencode/src/provider/transform.ts → applyCaching() in
sst/opencode.
Open issues: #25984 (Bifrost/LiteLLM → Bedrock), #26460 (Xiaomi MiMo).
When the user routes Anthropic-shaped models through an
OpenAI-compatible proxy (LiteLLM, Bifrost, or any
@ai-sdk/openai-compatible adapter), OpenCode falls through to the
OpenAI caching path and sets promptCacheKey (OpenAI shape). The
proxy forwards this verbatim to the Anthropic backend, which ignores
it. Result: 0% cache hit rate on what is otherwise the canonical
"long agent loop on Claude" use case.
Affected routes:
@ai-sdk/openai-compatible endpoint with Claude backendBroaden the detection predicate so OpenAI-compatible adapters with Anthropic-shaped models get Anthropic-style caching:
--- a/packages/opencode/src/provider/transform.ts
+++ b/packages/opencode/src/provider/transform.ts
@@ function applyCaching(msgs, model)
if (
model.providerID === "anthropic" ||
model.api.id.includes("anthropic") ||
model.api.id.includes("claude") ||
- model.api.npm === "@ai-sdk/anthropic"
+ model.api.npm === "@ai-sdk/anthropic" ||
+ model.api.npm === "@ai-sdk/google-vertex/anthropic" ||
+ // OpenAI-compatible proxies routing to Anthropic-shaped backends
+ (model.api.npm === "@ai-sdk/openai-compatible" &&
+ (model.api.id.toLowerCase().includes("claude") ||
+ model.api.id.toLowerCase().includes("anthropic") ||
+ model.api.id.toLowerCase().includes("mimo"))) ||
+ // MiniMax and other Anthropic-shaped non-Anthropic models
+ model.api.id.startsWith("minimax/")
) {
// Apply Anthropic-style cache_control on message blocks
}
Optionally factor the predicate into a named helper
(isAnthropicShapedRoute(model)) so the same check can be reused
elsewhere in OpenCode.
provider:
openai-compatible:
baseURL: http://localhost:4000/v1
models:
- claude-3-5-sonnet-bedrock
prompt_cache_key, no
cache_control markers; response cache_read_input_tokens always 0.cache_control on system + last
stable message; response shows cache_read_input_tokens > 0 on
turn 2.This is a routing-layer detection bug, not a caching-logic bug. The caching CODE is fine; it just never runs for these models because the predicate didn't anticipate proxy-shaped routes.
Related skills:
Full audit: audits/opencode.md.
Aider uses 5min TTL by default and works around long pauses with keepalive pings. Wire up the 1h TTL beta instead.
Aider's --cache-prompts is off by default. Flip it on for supported models.
Stop Cline from burning a cache breakpoint on the volatile current user message every turn.
Cline OpenAI native provider sends no prompt_cache_key. Add a stable per-task key so cached_tokens stops being zero.
Cline's system prompt includes a timestamp that may be recomputed per request, invalidating the system-prompt cache.
Continue's prompt caching is opt-in via config and off by default. Flip the default to systemAndTools.