fix(plugin): map real pricing from /v1/model/info into cost field - #16
Conversation
toConfigModel() never read input_cost_per_token/output_cost_per_token from LiteLLM's /v1/model/info response, so every discovered model landed in opencode.json without a cost field. OpenCode's own default (0) then made every call look free in the picker and in `/cost`, regardless of what the proxy actually billed. Map those two fields into OpenCode's cost block, converting LiteLLM's USD-per-token to OpenCode's USD-per-million-token convention. Models LiteLLM has no price anchor for (e.g. rerank) are left without a cost field, same as before — this reports real prices, it doesn't invent ones for models that don't have one. Verified live against a self-hosted LiteLLM proxy: discovered cost matched litellm's own model_info exactly across 15 priced models, and a real chat completion's session cost matched prompt_tokens * input_cost_per_token + completion_tokens * output_cost_per_token to the cent.
📝 WalkthroughWalkthroughThe change adds optional LiteLLM input and output pricing fields, converts available per-token prices to OpenCode’s per-million-token ChangesPricing propagation
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant LiteLLM as LiteLLM /v1/model/info
participant Enrichment as Model enrichment
participant OpenCode as OpenCode model configuration
LiteLLM->>Enrichment: input and output cost per token
Enrichment->>OpenCode: converted per-million-token cost
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/plugin/index.ts`:
- Around line 123-132: The cost mapping around LiteLLMModel pricing must not
represent a missing side as zero. Update the condition and cost construction so
cost is emitted only when both input_cost_per_token and output_cost_per_token
are present, unless the target schema explicitly supports partial cost objects;
preserve reported values and add fixtures covering input-only and output-only
pricing.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2b5d7541-45c2-4e94-9309-de51d42a4408
📒 Files selected for processing (4)
CHANGELOG.mdREADME.mdsrc/plugin/index.tssrc/types/index.ts
## [0.7.1](v0.7.0...v0.7.1) (2026-08-04) ### Bug Fixes * **plugin:** map real pricing from /v1/model/info into cost field ([#16](#16)) ([907b496](907b496))
Summary
Discovered models never got a
cost—toConfigModel()reads/v1/model/infoformode, token limits, and capability flags, but dropsinput_cost_per_token/output_cost_per_tokenon the floor. Every model lands inopencode.jsonwithout acostfield, so OpenCode's own default (0) makes every call look free in the picker and in/cost, regardless of what the proxy actually bills.Type of change
Checklist
npm run typecheckpassesCHANGELOG.mdupdated under## [Unreleased]How was this tested?
Live, against a self-hosted LiteLLM 1.92.0 proxy (21 models, 15 chat + 6 non-chat) fronting real vLLM/NIM backends, with OpenCode 1.18.13.
opencode models <provider> --verbose: all models that have a price in the proxy'smodel_listnow carry the matchingcostin the discovered entry (USD/token from/v1/model/infoconverted to USD/1M-token, OpenCode's convention). Models the proxy has no price for are left without acostfield — not defaulted to0— same as before this fix, so nothing is falsely marked free.costmatchedprompt_tokens * input_cost_per_token + completion_tokens * output_cost_per_tokencomputed from the proxy's own price table, to the fraction of a cent, across two independent runs.Screenshots / logs (optional)
Before (unpatched):
After (this PR), same model:
matching the proxy's configured
input_cost_per_token: 0.00000007/output_cost_per_token: 0.00000007exactly (×1e6).Summary by CodeRabbit
New Features
Documentation