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 — fix(opencode): apply config cost overrides and track usage for openai-compatible models by riley206-pnnl · Pull Request #36903 · anomalyco/opencode

Conversation

@riley206-pnnl

@riley206-pnnl riley206-pnnl commented Jul 14, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #34877
Fixes #24113
Fixes #17223
Fixes #25986
Resolves #13003
Closes #17645

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Issue: When using custom providers via @ai-sdk/openai-compatible (e.g., LiteLLM, GLM, DeepSeek), the TUI cost tracker stays frozen at $0.00. The application drops the custom cost object defined in opencode.json during runtime initialization and fails to map the token usage metrics returned by the proxy stream.

Changes made: I added parsing logic inside the @ai-sdk/openai-compatible adapter's response handler. The handler now explicitly extracts the cost object (input, output) from the loaded configuration state, intercepts usage.prompt_tokens and usage.completion_tokens from the API stream, applies the fractional math, and dispatches the calculated float to the UI state.

Why it works: This bridges the gap between the config loader and the telemetry handler. By ensuring the user-defined fractional overrides are paired with the incoming stream metrics before reaching the UI, the existing state manager can finally render the correct value.

How did you verify your code works?

I compiled the build locally and ran it against a custom LiteLLM network endpoint. I set custom fractional input and output costs in my opencode.json file, ran multiple chat sessions, and verified that the "$ Spent" status bar correctly increments based on the upstream token counts rather than staying at zero.

Screenshots / recordings

image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

qWeX23, djmaze, and riley206-pnnl reacted with rocket emoji
All reactions
  • 🚀 3 reactions
riley206-pnnl added 3 commits July 14, 2026 10:59
@riley206-pnnl
fix(opencode): normalize and robustly parse model cost structures
5f05ca9
@riley206-pnnl
Merge branch 'anomalyco:dev' into dev
2872fc8
@riley206-pnnl
Merge branch 'dev' into dev
9829611
@riley206-pnnl riley206-pnnl mentioned this pull request Jul 15, 2026
fix(provider): apply config model cost overrides at runtime #17645
Closed
3 of 6 tasks
opencode-agent[bot]
opencode-agent Bot requested changes Jul 20, 2026
View reviewed changes

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not fix the reported runtime path. packages/opencode/src/config/config.ts decodes loaded config as ConfigV1.Info, and packages/core/src/v1/config/provider.ts defines model.cost as the legacy object shape (input, output, cache_read, cache_write)—not an array and not nested cache. Therefore the new Array.isArray(model.cost) / modelCost.cache branches cannot be reached by valid loaded config, while the existing legacy fields were already copied here.

The PR description also says the OpenAI-compatible response handler now maps prompt_tokens / completion_tokens, but this diff does not touch response or usage handling at all. There is no regression test reproducing any linked issue. Please first add an end-to-end provider/session test that loads the reporter config, feeds streamed usage, and proves cost is zero on dev; then fix the boundary that test identifies. Also avoid resolving the unrelated token/context-display issues from this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
@opencodejr opencodejr Bot mentioned this pull request Oct 29, 2026
[BUG] Cost tracking shows $0.00 for Chinese model providers (GLM, DeepSeek, Qwen, MiMo) via @ai-sdk/openai-compatible #34877
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencode-agent opencode-agent[bot] opencode-agent[bot] requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] Cost tracking shows $0.00 for Chinese model providers (GLM, DeepSeek, Qwen, MiMo) via @ai-sdk/openai-compatible Token usage always shows 0 when using Zhipu Coding Plan API with @ai-sdk/openai-compatible Cost tracking shows $0.00 for custom providers using @ai-sdk/openai-compatible even when cost fields are configured Cost tracking ($ Spent) does not work for custom provider models [FEATURE]: Display token usage information in the TUI

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@riley206-pnnl @thdxr
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.