Skip to content

fix(provider): apply config model cost overrides at runtime - #17645

Closed
mollux wants to merge 1 commit into
anomalyco:devfrom
mollux:fix/runtime-model-cost-config-override
Closed

mollux wants to merge 1 commit into
anomalyco:devfrom
mollux:fix/runtime-model-cost-config-override

Conversation

@mollux

@mollux mollux commented Mar 15, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #17223

Type of change

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

What does this PR do?

This fixes a runtime gap where model prices from config could be present in resolved config but not applied on the final model object used for usage/cost calculations.
The change applies config model cost overrides during provider model finalization so cost values are consistently present before runtime usage math runs.

How did you verify your code works?

  • Added/updated provider test coverage for model cost override behavior via config content.
  • Ran focused tests locally:
bun test test/provider/provider.test.ts -t "OPENCODE_CONFIG_CONTENT overrides cost for configured model|model cost overrides existing cost values"

Screenshots / recordings

N/A (non-UI change)

Checklist

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

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@mollux
mollux marked this pull request as ready for review March 21, 2026 16:51
@jabr

jabr commented Mar 25, 2026

Copy link
Copy Markdown

Any chance this will be merged soon? I use API accounts directly with providers that are often missing from the standard models.dev data, and thus specify most of my model configs (and pricing info) directly in my opencode.json config. This means that OpenCode's cost estimates are wildly inaccurate for me, even though the token usage counts are correct.

In this example, it appears to be pricing the cached reads at $0 even though I have the correct config for $0.06/Mtok. The 1.5M input + 68.7K output looks to equal the $0.54 total it reports, but it's missing $0.66 of cached read cost:

┌────────────────────────────────────────────────────────┐
│                      MODEL USAGE                       │
├────────────────────────────────────────────────────────┤
│ novita-ai/novita-ai/minimax/minimax-m2.7               │
│  Messages                                          216 │
│  Input Tokens                                     1.5M │
│  Output Tokens                                   68.7K │
│  Cache Read                                      11.0M │
│  Cache Write                                         0 │
│  Cost                                          $0.5447 │
└────────────────────────────────────────────────────────┘

@mollux
mollux force-pushed the fix/runtime-model-cost-config-override branch 2 times, most recently from 1873952 to 4150f92 Compare April 14, 2026 11:19
@mollux
mollux force-pushed the fix/runtime-model-cost-config-override branch from 4150f92 to e72cdfb Compare June 27, 2026 20:30
@djmaze

djmaze commented Jul 1, 2026

Copy link
Copy Markdown

Somehow this PR only contains a test but not real change. @mollux Can you fix this?

@hyqf98

hyqf98 commented Jul 2, 2026

Copy link
Copy Markdown

This PR has been open for nearly 4 months and is critical for anyone using custom providers (LiteLLM proxies, Chinese model providers like GLM/DeepSeek/Qwen, OpenAI-compatible endpoints).

The cost config field in opencode.json model definitions has zero effect — $ Spent stays at $0.00 regardless of token usage. This affects a huge number of users outside the Anthropic/OpenAI ecosystem.

Real-world impact: Users in China using GLM-5.2, DeepSeek V4, MiMo, etc. via @ai-sdk/openai-compatible cannot see any cost tracking. Related issues: #24113, #17223.

The fix looks solid with test coverage. Could the maintainers prioritize reviewing and merging this? Many users are resorting to third-party plugins (opencode-throughput, opencode-tokenscope) as workarounds because the built-in cost tracking is completely broken for custom providers.

@djmaze

djmaze commented Jul 3, 2026

Copy link
Copy Markdown

Everyone in here who is not a hallucinating bot, raise your hands. ✋

@buildgreatthings

Copy link
Copy Markdown

+1

1 similar comment
@a-peleshok

Copy link
Copy Markdown

+1

@riley206-pnnl

Copy link
Copy Markdown

real fix here #36903

@rekram1-node

Copy link
Copy Markdown
Collaborator

This adds nothing, closing

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

8 participants