Skip to content

Cost tracking ($ Spent) does not work for custom provider models #17223

Closed as not planned

Description

@delflein

Problem

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

  1. Configure a custom provider in opencode.jsonc with cost fields specified per the config schema:
{
  "provider": {
    "my-provider": {
      "name": "My Provider",
      "npm": "@ai-sdk/openai-compatible",
      "models": {
        "my-model": {
          "name": "My Model",
          "cost": {
            "input": 0.0000055,
            "output": 0.0000275,
            "cache_read": 5.5e-7,
            "cache_write": 0.000006875
          },
          "limit": { "context": 200000, "output": 64000, "input": 200000 },
          "tool_call": true
        }
      },
      "options": {
        "baseURL": "https://my-proxy.example.com"
      }
    }
  }
}
  1. Start a session using the custom provider model.
  2. 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

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 12, 2026
  2. mollux commented on Mar 21, 2026

    @mollux

    @delflein I made a PR to address this, see #17645, does this also solve your problem?

  3. nstoeckigt commented on Mar 31, 2026

    @nstoeckigt

    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:

    • 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.

  4. added 8 commits that reference this issue on Apr 25, 2026
  5. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. maurerle commented on May 8, 2026

    @maurerle

    @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.

  7. JGuck commented on May 28, 2026

    @JGuck

    I can confirm that cost calculation is working when realizing costs are per M token.

  8. laiweihwa commented on Jun 19, 2026

    @laiweihwa

    My custom provider returns cost and opencode ignores it. I believe opencode-plugin-litellm is to blame, in my case.

  9. github-actions commented on Aug 19, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions