GeezerVison is showing github.com — Cost tracking shows $0.00 for custom providers using @ai-sdk/openai-compatible even when cost fields are configured · Issue #24113 · anomalyco/opencode
Cost tracking shows $0.00 for custom providers using @ai-sdk/openai-compatible even when cost fields are configured #24113DescriptionDescription
When using a custom provider configured via opencode.json with @ai-sdk/openai-compatible, the UI 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 similar issue to what was reported on the popular fork anomalyco/opencode#17223.
Plugins
No response
OpenCode version
1.14.22
Steps to reproduce
- Configure a custom provider in
opencode.json with @ai-sdk/openai-compatible and cost fields specified:
{
"provider": {
"my-proxy": {
"name": "My LiteLLM Proxy",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://proxy.example.com/v1",
"apiKey": "sk-..."
},
"models": {
"my-model": {
"name": "My Model",
"cost": {
"input": 5.5e-07,
"output": 2.75e-06,
"cache": {
"read": 5.5e-08,
"write": 6.875e-07
}
},
"limit": {
"context": 200000,
"output": 64000
}
}
}
}
}
}
- Start a session using the custom provider model.
- Send messages and observe the cost display in the status bar.
Expected Behavior
The UI should calculate and display a running cost using either:
- The cost values defined in the model config combined with the token usage from the API response (usage.prompt_tokens, usage.completion_tokens), OR
- The cost header returned by the proxy (e.g., x-litellm-response-cost).
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 (LiteLLM proxy) correctly returns token usage in the response body:
usage: {
prompt_tokens: 10,
completion_tokens: 52,
total_tokens: 62
}
- The upstream API also returns a cost header: x-litellm-response-cost: 0.0002015
- OpenCode appears to neither calculate cost from token counts nor read the x-litellm-response-cost header.
Screenshot and/or share link
No response
Operating System
Ubuntu 24
Terminal
No response Reacted by Hannes, Tomáš (Tonda) Kalina and Brendan LeFebvre Activityadded coreAnything pertaining to core functionality of the application (opencode server stuff) on Apr 24, 2026github-actions commented on Apr 24, 2026 This issue might be a duplicate of existing issues. Please check:
If this is indeed the same underlying issue, please consider adding your specific details (the @ai-sdk/openai-compatible configuration and x-litellm-response-cost header context) as a comment on #17223 instead. removed bugSomething isn't working coreAnything pertaining to core functionality of the application (opencode server stuff) on May 3, 2026maurerle commented on May 8, 2026 Yes, duplicate of #17223:
Your values in the config are too low to create meaningful steps.
Try 0.3 as a cost for example, which is in $ per 1M tokens. fabienbarbaud commented on May 9, 2026 Update — confirmed fixed on my end.
@maurerle was right about the cost scale — my values were per-token instead of per-1M-tokens. That fixed the $0.00 display.
However, I also had two related config gaps that left the UI broken even after fixing costs:
1. limit.context is required for the % usage display
OpenCode uses model.limit.context for the percentage calculation, not model.context_window. Without it, context always shows 0% regardless of actual token usage.
2. includeUsage: true is needed in provider options
When using @ai-sdk/openai-compatible with a LiteLLM proxy, streaming responses don't include token counts by default. Both cost and context tracking fail silently without this flag.
Full working config excerpt
{
"provider": {
"litellm": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://proxy.example.com/v1",
"includeUsage": true
},
"models": {
"my-model": {
"limit": { "context": 202000, "output": 25344 },
"cost": { "input": 1.4, "output": 4.4 }
}
}
}
}
}
All three (cost scale, limit.context, includeUsage) were required to get cost tracking and context percentage working correctly.
Closing this as resolved — the underlying behavior could use better docs, but it's working as designed once configured properly.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|