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
Cost tracking ($ Spent) does not work for custom provider models #17223
When using a custom provider configured via opencode.jsonc with @ai-sdk/openai-compatible, the UI does not track or display $ Spent. The cost remains at $0.00 regardless of token usage.
Built-in providers get their pricing data from models.dev and cost tracking works for those. For custom providers, the cost config fields are available in the schema but do not appear to have any effect on the UI.
Steps to Reproduce
Configure a custom provider in opencode.jsonc with cost fields specified per the config schema:
Send messages and observe the cost display in the UI.
Expected Behavior
The UI calculates and displays a running cost using the cost values defined in the model config and the token usage from the response.
Actual Behavior
$ Spent remains at $0.00 for the entire session. The cost config fields on custom provider models have no observable effect.
Environment
Custom provider backed by a LiteLLM proxy via @ai-sdk/openai-compatible
Multiple models tested — issue is consistent across all custom provider models
cost structure matches the config JSON schema at https://opencode.ai/config.json, including input, output, cache_read, cache_write, and context_over_200k sub-fields
Reacted by Jessica Köhnke, Juan Abia, Codinator007, Stefano Ciarcià, nguyendown, Mark Nguyen, Michael Monaghan, Jose Constela, Matt Sawyer, Wieland Strauß and 16 more
I'm running OpenCode with LiteLLM as an intermediate proxy to Anthropic (claude). The model is configured as a custom provider using litellm/anthropic/claude as the model ID.
Setup:
OpenCode connects to a local LiteLLM instance
LiteLLM forwards requests to Anthropic
Provider configured as a custom openai-compatible provider pointing to the LiteLLM endpoint
Observed behavior:
Token counts (input/output) are displayed correctly in the OpenCode session overview
spent $ remains at $0.00 for every session
Expected behavior:
spent $ should reflect the actual cost of the session
Workaround:
LiteLLM's own dashboard correctly tracks and displays costs — currently using that as the only reliable cost tracking source
Root cause (suspected):
OpenCode receives token counts from the LiteLLM response but has no way to map them to a cost since it doesn't know the pricing for the underlying model behind the proxy. LiteLLM does return cost information in its response metadata (e.g. x-litellm-response-cost header and usage.cost in some response formats) — it would be great if OpenCode could pick that up when available.
Reacted by Michael Monaghan, Michał Polewczak, Justin Travaille, Calle Kabo, Vlad Goldman, darenegade, Jens Grehling, Ryan Beall, Evan, Martin Honermeyer and 3 more
@delflein I can not reproduce this issue.
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.
@nstoeckigt respecting x-litellm-response-cost headers is a different feature request.
Activity
mollux commentedon Mar 21, 2026
@delflein I made a PR to address this, see #17645, does this also solve your problem?
nstoeckigt commentedon Mar 31, 2026
Reproducing with LiteLLM as a proxy
I'm running OpenCode with LiteLLM as an intermediate proxy to Anthropic (claude). The model is configured as a custom provider using litellm/anthropic/claude as the model ID.
Setup:
Observed behavior:
Expected behavior:
Workaround:
Root cause (suspected):
OpenCode receives token counts from the LiteLLM response but has no way to map them to a cost since it doesn't know the pricing for the underlying model behind the proxy. LiteLLM does return cost information in its response metadata (e.g. x-litellm-response-cost header and usage.cost in some response formats) — it would be great if OpenCode could pick that up when available.
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
roadmap: ultraworkers#213 filed — OpenAiUsage struct does not deseria…
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
roadmap: #213 filed — OpenAiUsage struct does not deserialize prompt_…
maurerle commentedon May 8, 2026
@delflein I can not reproduce this issue.
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.
@nstoeckigt respecting x-litellm-response-cost headers is a different feature request.
JGuck commentedon May 28, 2026
I can confirm that cost calculation is working when realizing costs are per M token.
laiweihwa commentedon Jun 19, 2026
My custom provider returns cost and opencode ignores it. I believe
opencode-plugin-litellmis to blame, in my case.github-actions commentedon Aug 19, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.