Skip to content

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

@delflein

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions