Skip to content

feat: read costs per model - #11

Closed
JCHacking wants to merge 2 commits into
yuseferi:mainfrom
JCHacking:costs
Closed

feat: read costs per model#11
JCHacking wants to merge 2 commits into
yuseferi:mainfrom
JCHacking:costs

Conversation

@JCHacking

@JCHacking JCHacking commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Initial implementation to read the cost of the models

Type of change

  • 🐛 Bug fix (non-breaking)
  • ✨ New feature (non-breaking)
  • 💥 Breaking change
  • 📝 Documentation only
  • 🔧 Internal / refactor

Checklist

  • npm run typecheck passes
  • No new runtime dependencies (or justified in this PR description)
  • README updated if public API or behavior changed
  • CHANGELOG.md updated under ## [Unreleased]
  • Commit messages follow Conventional Commits

How was this tested?

I tested it on my OpenCode with Litellm, and the costs displayed correctly.

Screenshots / logs (optional)

Summary by CodeRabbit

  • New Features

    • Added model pricing details for input, output, and cached tokens.
    • Pricing is now displayed per million tokens when available.
    • Pricing metadata is enriched from additional model configuration details.
  • Bug Fixes

    • Improved handling of missing or zero pricing data.
    • Model discovery continues successfully when pricing information is unavailable, defaulting costs to zero.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Model discovery now retrieves /v1/model/info metadata, enriches missing pricing fields, and maps input, output, and cache token costs into OpenCode models with zero-value fallbacks.

Changes

Model cost discovery and mapping

Layer / File(s) Summary
Cost metadata contract and enrichment
src/types/index.ts, src/utils/litellm-api.ts
Adds optional token-cost fields to LiteLLMModelInfo and fills missing values from litellm_params.
Discovery pipeline and V2 model mapping
src/plugin/discover.ts, src/plugin/build-model.ts
Runs model and model-info discovery concurrently, tolerates model-info failures, and maps discovered costs into V2 models using per-million-token scaling.
Config model mapping and release note
src/plugin/index.ts, CHANGELOG.md
Passes model-info data into config conversion, maps scaled token and cache costs, and documents the new /v1/model/info cost source.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant discoverBucket
  participant LiteLLM
  participant buildModelV2
  participant OpenCodeModel
  discoverBucket->>LiteLLM: discoverLiteLLMModels()
  discoverBucket->>LiteLLM: discoverLiteLLMModelInfo()
  LiteLLM-->>discoverBucket: models and cost metadata
  discoverBucket->>buildModelV2: model and LiteLLMModelInfo
  buildModelV2->>OpenCodeModel: create scaled input/output/cache costs
Loading

Possibly related PRs

Suggested reviewers: yuseferi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly describes the main change: reading per-model costs.
✨ 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.

@yuseferi

yuseferi commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Sorry, I reviewed the other one first mistakenly and both are doing the same!
It's already merged!
#16

Thanks for your contribution, and looking forward for your next PR <3

@yuseferi yuseferi closed this Aug 4, 2026
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.

3 participants