Skip to content

Prompt Caching Not Working for Xiaomi/MiMo Models #26460

@xenstar

Description

@xenstar

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions