anomalyco / anomalyco/opencode

Incorrect cost calculation for generic OpenAI-compatible providers (Zenmux) using prefixed model IDs

Open
#44,410 1 comment 0 reactions 1 assignee View on GitHub

@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 connect as 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
  • Opencode TUI:
    • Displayed Cost: $0.04

The $0.04 figure corresponds strictly to the Output Cost, completely ignoring the Input Cost.

Expected Behavior

Opencode should either:

  1. Strip vendor prefixes when doing local pricing lookups for generic OpenAI-compatible providers.
  2. 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
  1. Connect a generic OpenAI-compatible aggregator provider (Zenmux.ai) using opencode connect.
  2. Select a model using a vendor prefix in its ID (e.g., deepseek/deepseek-v4-flash).
  3. Run a session generating both input and output usage across multiple requests.
  4. 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)
Image Image Image
Operating System

Linux / Ubuntu 24.04.04 LTS

Terminal

Xfce Terminal with bash

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.