Skip to content

Cost tracking shows $0.00 for custom providers using @ai-sdk/openai-compatible even when cost fields are configured #24113

Closed

Description

@fabienbarbaud

Description

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

  1. 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
          }
        }
      }
    }
  }
}
  1. Start a session using the custom provider model.
  2. 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

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 24, 2026
  2. github-actions commented on Apr 24, 2026

    @github-actions
    Contributor

    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.

  3. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. maurerle commented on May 8, 2026

    @maurerle

    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.

  5. fabienbarbaud commented on May 9, 2026

    @fabienbarbaud
    Author

    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.

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