Skip to content

fix(plugin): map real pricing from /v1/model/info into cost field - #16

Merged
yuseferi merged 1 commit into
yuseferi:mainfrom
zyc:fix/model-cost-from-model-info
Aug 4, 2026
Merged

fix(plugin): map real pricing from /v1/model/info into cost field#16
yuseferi merged 1 commit into
yuseferi:mainfrom
zyc:fix/model-cost-from-model-info

Conversation

@zyc

@zyc zyc commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Discovered models never got a costtoConfigModel() reads /v1/model/info for mode, token limits, and capability flags, but drops input_cost_per_token/output_cost_per_token on the floor. Every model lands in opencode.json without a cost field, 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

  • 🐛 Bug fix (non-breaking)

Checklist

  • npm run typecheck passes
  • No new runtime dependencies
  • README updated (new "Real pricing" row in the features table, "How it works" step 4)
  • CHANGELOG.md updated under ## [Unreleased]
  • Commit messages follow Conventional Commits

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's model_list now carry the matching cost in the discovered entry (USD/token from /v1/model/info converted to USD/1M-token, OpenCode's convention). Models the proxy has no price for are left without a cost field — not defaulted to 0 — same as before this fix, so nothing is falsely marked free.
  • A real chat completion's exported session cost matched prompt_tokens * input_cost_per_token + completion_tokens * output_cost_per_token computed from the proxy's own price table, to the fraction of a cent, across two independent runs.

Screenshots / logs (optional)

Before (unpatched):

"cost": { "input": 0, "output": 0, "cache": { "read": 0, "write": 0 } }

After (this PR), same model:

"cost": { "input": 0.07, "output": 0.07, "cache": { "read": 0, "write": 0 } }

matching the proxy's configured input_cost_per_token: 0.00000007 / output_cost_per_token: 0.00000007 exactly (×1e6).

Summary by CodeRabbit

  • New Features

    • Added real input and output token pricing for discovered models.
    • Pricing is converted to per-million-token costs for display.
    • Models without available pricing remain unpriced.
  • Documentation

    • Updated the README and changelog to describe pricing enrichment and handling of unavailable pricing.

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.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds optional LiteLLM input and output pricing fields, converts available per-token prices to OpenCode’s per-million-token cost fields, omits costs when pricing is unavailable, and documents the behavior.

Changes

Pricing propagation

Layer / File(s) Summary
Pricing contract and enrichment
src/types/index.ts, src/plugin/index.ts
LiteLLM model types now include optional input and output token prices. Model enrichment copies these values from LiteLLM metadata.
Cost mapping and documentation
src/plugin/index.ts, README.md, CHANGELOG.md
Generated OpenCode models conditionally include converted per-million-token costs. The README and changelog document the pricing behavior.

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
Loading

Possibly related PRs

Suggested reviewers: yuseferi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes mapping LiteLLM pricing into the OpenCode cost field.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between baa8874 and 218082c.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • README.md
  • src/plugin/index.ts
  • src/types/index.ts

Comment thread src/plugin/index.ts
@yuseferi
yuseferi merged commit 907b496 into yuseferi:main Aug 4, 2026
2 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 4, 2026
## [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))
@yuseferi yuseferi mentioned this pull request Aug 4, 2026
10 tasks
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.

2 participants