GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cost tracking shows $0.00 for custom providers using @ai-sdk/openai-compatible even when cost fields are configured · Issue #24113 · anomalyco/opencode

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Cost tracking shows $0.00 for custom providers using @ai-sdk/openai-compatible even when cost fields are configured#24113
Copy link
Assignees
nexxeln

Description

@fabienbarbaud
fabienbarbaud
opened on Apr 24, 2026
Issue body actions

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

Reacted by Hannes, Tomáš (Tonda) Kalina and Brendan LeFebvre

Activity

  1. fabienbarbaud
    added
    bugSomething isn't working
    on Apr 24, 2026
  2. github-actions
    assigned
    rekram1-node
    on Apr 24, 2026
  3. github-actions
    added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 24, 2026
  4. github-actions commented on Apr 24, 2026

    @github-actions
    github-actionsBot
    on Apr 24, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • Cost tracking ($ Spent) does not work for custom provider models #17223: Cost tracking ($ Spent) does not work for custom provider models — same symptom of $0.00 cost display for custom providers (you also reference this issue in your report)

    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.

  5. thdxr
    removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. thdxr
    assigned
    nexxeln
    and unassigned
    rekram1-node
    on May 3, 2026
  7. maurerle commented on May 8, 2026

    @maurerle
    maurerle
    on May 8, 2026
    More actions

    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.

  8. fabienbarbaud commented on May 9, 2026

    @fabienbarbaud
    fabienbarbaud
    on May 9, 2026
    Author
    More actions

    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.

  9. fabienbarbaud
    closed this as completedon May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @nexxeln
    nexxeln

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.