anomalyco / anomalyco/opencode
Incorrect cost calculation for generic OpenAI-compatible providers (Zenmux) using prefixed model IDs
@MrMushrooooom is already working on this.
Since Aug 23, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Environment
- Opencode Version: 1.8.18
- OS: Linux
- Provider: Zenmux (configured via
opencode connectas OpenAI-compatible) - Model used:
deepseek/deepseek-v4-flash
Summary
When using generic OpenAI-compatible proxy providers like Zenmux, session cost calculation in the TUI is inaccurate. While OpenRouter correctly reports total costs, generic providers using prefixed model IDs (vendor/model-name) seem to default input token costs to $0.00, displaying only the output token cost.
Root Cause / Hypothesis
OpenRouter has native integration/pricing retrieval in Opencode. However, for generic OpenAI-compatible endpoints, Opencode falls back to a local model pricing lookup. The vendor prefix (e.g., deepseek/ in deepseek/deepseek-v4-flash) prevents matching the model in the internal pricing table, causing input cost calculation to default to 0.
Proof
In a session with 57 API calls using deepseek/deepseek-v4-flash via Zenmux:
- Zenmux Dashboard:
- Input Cost:
$0.1533(2.28M tokens) - Output Cost:
$0.0410(32.60K tokens) - Total Cost:
$0.1944
- Input Cost:
- Opencode TUI:
- Displayed Cost:
$0.04
- Displayed Cost:
The $0.04 figure corresponds strictly to the Output Cost, completely ignoring the Input Cost.
Expected Behavior
Opencode should either:
- Strip vendor prefixes when doing local pricing lookups for generic OpenAI-compatible providers.
- Allow fallback/custom token pricing definitions in configuration for non-standard providers.
Actual Behavior
Input costs are calculated as $0 when the model string contains a vendor prefix on generic OpenAI-compatible endpoints.
Plugins
none
OpenCode version
1.8.18
Steps to reproduce
- Connect a generic OpenAI-compatible aggregator provider (Zenmux.ai) using
opencode connect. - Select a model using a vendor prefix in its ID (e.g.,
deepseek/deepseek-v4-flash). - Run a session generating both input and output usage across multiple requests.
- Compare the session cost shown in the OpenCode TUI with the actual costs logged on the provider dashboard.
Observed: The OpenCode TUI displays $0.04, which strictly equals the output token cost ($0.0410). The input token cost ($0.1533) is completely ignored/calculated as $0.
Expected: Total session cost should sum both input and output token costs ($0.1944).
Screenshot and/or share link
Comparison from a 57-request session:
- Zenmux Dashboard: Input $0.1533 (2.28M tokens) | Output $0.0410 (32.60K tokens) | Total $0.1944
- OpenCode TUI: Displays $0.04 (matches Output Cost only)
Operating System
Linux / Ubuntu 24.04.04 LTS
Terminal
Xfce Terminal with bash
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.