GeezerVison is showing github.com — [BUG] Cost tracking shows $0.00 for Chinese model providers (GLM, DeepSeek, Qwen, MiMo) via @ai-sdk/openai-compatible · Issue #34877 · anomalyco/opencode
[BUG] Cost tracking shows $0.00 for Chinese model providers (GLM, DeepSeek, Qwen, MiMo) via @ai-sdk/openai-compatible #34877DescriptionDescription
When using Chinese model providers configured via opencode.json with @ai-sdk/openai-compatible, the TUI does not track or display $ Spent. The cost remains at $0.00 regardless of token usage, even when cost fields are explicitly configured per the config schema.
This is a significant pain point for users in China who rely on providers like Zhipu (GLM-5.2), DeepSeek (V4 Pro), Xiaomi (MiMo), Alibaba (Qwen), etc. — none of which use Anthropic/OpenAI native APIs.
Related
Steps to reproduce
- Configure a Chinese model provider in
opencode.json:
{
"provider": {
"modelhub": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"apiKey": "sk-...",
"baseURL": "https://modelhub.example.com/v1"
},
"models": {
"glm-5.2": {
"name": "glm-5.2",
"cost": {
"input": 0.000001178,
"output": 0.000004123
},
"limit": {
"context": 1000000
}
}
}
}
},
"model": "modelhub/glm-5.2"
}
- Start a session and send messages.
- Observe the cost display in the TUI status bar — it stays at
$0.00.
Expected Behavior
OpenCode should calculate cost using the cost fields defined in the model config combined with token usage from the API response (usage.prompt_tokens, usage.completion_tokens).
Actual Behavior
$ Spent remains at $0.00 for the entire session.
- The
cost config fields on custom provider models have no observable effect.
- The upstream API correctly returns token usage in the response body.
Environment
- OpenCode version: latest (1.14.x)
- OS: macOS
- Provider:
@ai-sdk/openai-compatible with Chinese model endpoints (GLM-5.2, DeepSeek V4 Pro, MiMo V2 Pro)
Impact
This affects all users using non-Anthropic/non-OpenAI providers — which is a massive user base in China and other regions. Many are resorting to third-party plugins (opencode-throughput with manual pricing configs) as workarounds.
PR #17645 already has a working fix with test coverage. Could the team prioritize reviewing it? Activitygithub-actions commented on Jul 2, 2026 This issue might be a duplicate of existing issues. Please check:
(Note: #24113 and #17223 are already referenced in the issue body, but #25986 in particular covers the same Zhipu/@ai-sdk/openai-compatible combination.) gabrielandujar commented on Aug 8, 2026 Additional reproduction with native OpenAI provider:
I reproduced this issue with a native OpenAI provider (not @ai-sdk/openai-compatible). When using GPT-5.6 via OpenCode's built-in OpenAI provider, token usage IS tracked correctly in the sidebar (tokens input/output update in real-time, context % updates).
This confirms:
- OpenCode's token tracking pipeline works (plugin version 1.18.x)
- The issue is isolated to the @ai-sdk/openai-compatible adapter — it receives usage data from the provider but does not propagate it to OpenCode's internal tracking
- SQLite DB columns (tokens_input, tokens_output, cost) remain at 0 for all openai-compatible sessions
Provider response verified independently — the underlying API returns usage correctly. The gap is in how OpenCode consumes usage from the openai-compatible adapter vs native providers. mohagan9 commented on Sep 30, 2026 I am seeing the same issue for openai/gpt-6-luna. Note I selected it verbatim from the models list, as per my opencode.jsonc. (I did not use Luna latest from the list).
I had spent at least $0.10 at the time of the screenshot opencodejr commented on Oct 29, 2026 Thanks for the detailed report, and for linking the related work!
This report is about OpenCode 1.14.x, which is v1. v1 now only gets fixes for critical bugs (data loss, security problems, or breakage with no workaround). A wrong cost display is unlikely to be fixed there. The earlier fix PRs (#17645, #36903) were closed for the same reason; maintainers asked for the fix to be ported to v2.
Please try OpenCode v2 (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0). If cost still shows $0.00 on v2 with the same cost config, please reply here or open a new issue with your v2 version (opencode --version) and config. Also reply if you think this is critical for v1.
Related issues:
opencodejr commented on Oct 30, 2026 We haven't heard back, so I'm closing this as not planned. The report is about OpenCode v1 (1.14.x), and v1 only gets critical fixes. The $0.00 cost display for @ai-sdk/openai-compatible providers doesn't meet that bar.
If you still see $0.00 on OpenCode v2 with the same cost config, please open a new issue with your opencode --version output and config. The closest open report is #45483. Thanks again for the detailed write-up!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|