Description
Summary
When using OpenCode with Xiaomi's MiMo API directly, prompt caching (cache_control headers) is never applied, resulting in 0% cache hit rate and significantly higher token costs. In contrast, using the same models through OpenRouter achieves 90-95% cache hit rates because OpenRouter handles the caching headers correctly.
Root Cause: In opencode's source code (node-Bpcfl-9_.js:314466-314468), the applyCaching() function is only called for specific providers:
if ((model.providerID === "anthropic" ||
model.providerID === "google-vertex-anthropic" ||
model.api.id.includes("anthropic") ||
model.api.id.includes("claude") ||
model.id.includes("anthropic") ||
model.id.includes("claude") ||
model.api.npm === "@ai-sdk/anthropic" ||
model.api.npm === "@ai-sdk/alibaba") && ...)
MiMo uses @ai-sdk/openai-compatible which is NOT included in this condition.
The fix: opencode needs to add @ai-sdk/openai-compatible to the caching condition. This is a bug/missing feature in opencode.
Description
Summary
When using OpenCode with Xiaomi's MiMo API directly, prompt caching (
cache_controlheaders) is never applied, resulting in 0% cache hit rate and significantly higher token costs. In contrast, using the same models through OpenRouter achieves 90-95% cache hit rates because OpenRouter handles the caching headers correctly.Root Cause: In opencode's source code (node-Bpcfl-9_.js:314466-314468), the applyCaching() function is only called for specific providers:
if ((model.providerID === "anthropic" ||
model.providerID === "google-vertex-anthropic" ||
model.api.id.includes("anthropic") ||
model.api.id.includes("claude") ||
model.id.includes("anthropic") ||
model.id.includes("claude") ||
model.api.npm === "@ai-sdk/anthropic" ||
model.api.npm === "@ai-sdk/alibaba") && ...)
MiMo uses @ai-sdk/openai-compatible which is NOT included in this condition.
The fix: opencode needs to add @ai-sdk/openai-compatible to the caching condition. This is a bug/missing feature in opencode.