You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cache write tokens not accounted for when using OpenRouter, causing cost underestimation #18440
When a cache miss occurs via OpenRouter, opencode displays a near-zero cost even though the actual billing is much higher. This causes the in-app cost tracker to be way off from what OpenRouter bills.
The root cause: cacheWriteInputTokens falls back to 0 for OpenRouter because the code only looks for cache write tokens in anthropic and bedrock metadata. But OpenRouter actually exposes this in the usage response:
But since LiteLLM uses the OpenAI-compatible format, there's no metadata["bedrock"] or metadata["anthropic"] in the response. OpenCode only reads cache write tokens from provider-specific metadata, so cacheWriteInputTokens is always 0.
In our case, OpenCode shows ~$0.03 while LiteLLM reports ~$0.07 for the same session. The difference comes from 10798 cache_creation tokens priced at $3.00/M (regular input) instead of $3.75/M (cache write).
The fallback to input.usage.cacheWriteInputTokens proposed above would fix this for all OpenAI-compatible proxies.
Activity
iandreyshev commentedon Mar 24, 2026
We're hitting the same issue with LiteLLM proxy routing to AWS Bedrock (bedrock/us.anthropic.claude-sonnet-4-6).
LiteLLM correctly returns cache_creation_input_tokens and cache_read_input_tokens in the usage object:
But since LiteLLM uses the OpenAI-compatible format, there's no metadata["bedrock"] or metadata["anthropic"] in the response. OpenCode only reads cache write tokens from provider-specific metadata, so cacheWriteInputTokens is always 0.
In our case, OpenCode shows ~$0.03 while LiteLLM reports ~$0.07 for the same session. The difference comes from 10798 cache_creation tokens priced at $3.00/M (regular input) instead of $3.75/M (cache write).
The fallback to input.usage.cacheWriteInputTokens proposed above would fix this for all OpenAI-compatible proxies.
Count cache writes, not just cache hits