Skip to content

feat(costs): use bundled model prices by default - #1049

Merged
elyasmnvidian merged 1 commit into
mainfrom
emehtabuddin/desktop-prices-file
Oct 21, 2026
Merged

elyasmnvidian merged 1 commit into
mainfrom
emehtabuddin/desktop-prices-file

Conversation

@elyasmnvidian

@elyasmnvidian elyasmnvidian commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Before this PR, when a provider omitted a dollar charge and no price file was set, the server recorded the cost as unknown. Now the server and desktop app estimate costs from a price table bundled in the switchyard-costs crate. For example, calls to claude-opus-5-5 now get estimated costs and desktop baselines without a custom price file.

The table lists 35 exact model IDs: 15 direct OpenAI IDs, eight prefixed OpenAI IDs, codex-auto-review, seven direct Claude IDs, three OpenRouter Claude IDs, and azure/anthropic/claude-haiku-4-5. The bundled rates match OpenAI's prices, Anthropic's prices, and OpenRouter's model list as of October 21, 2026. codex-auto-review uses the gpt-6-sol rates. IDs with a provider prefix use list rates, so billed charges may differ. IDs must match exactly; unlisted IDs stay unknown.

For GPT-5.6 and newer, cache writes cost 1.25 times the input rate (OpenAI's 30-minute rate). Older OpenAI models charge the input rate for separately counted writes. Claude rates separate 5-minute and 1-hour writes. The table leaves out long-context and service-tier pricing, OpenAI's 12-hour cache writes, tool fees, and cache storage. Bundled rates change only with a release. ChatGPT subscription comparisons are estimates.

To use your own rates, pass --pricing-file PATH to the server or set pricing_file in desktop settings. The TOML or JSON file replaces the whole table. A missing, unreadable, or invalid configured file is an error. Provider-reported charges, including zero, take precedence over estimates. Missing usage or rates leave the estimate unknown, and changing rates does not reprice saved calls. The server loads rates at startup, and the desktop app loads them when it refreshes settings or usage; neither fetches prices over the network. Install creates no price file, and uninstall keeps custom price files. Users must convert or remove older inline [prices] settings by hand.

Testing

A local HTTP stub returned 10 uncached input tokens and 2 output tokens for azure/anthropic/claude-haiku-4-5. With routing logging on and no price file, the server recorded {"usd":0.00002,"source":"estimated"}. TOML and JSON price files that set input to $9 and output to $0 per million tokens both produced $0.00009. The stub checks Switchyard's cost math only; it does not check a provider's bill.

TOML price file used
["azure/anthropic/claude-haiku-4-5"]
input=9
output=0
cache_read=0
cache_write=0

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA-NeMo/Switchyard/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: c1a62075-d566-4937-9166-068a0661b5ba
📥 Commits

Reviewing files that changed from the base of the PR and between 2e9f94b and ed9cb2d.

📒 Files selected for processing: 6
  • crates/switchyard-desktop/prices.toml
  • crates/switchyard-desktop/src/bin/switchyard-desktop-install.rs
  • crates/switchyard-desktop/src/install.rs
  • crates/switchyard-desktop/src/install/windows.rs
  • crates/switchyard-desktop/tests/desktop.rs
  • scripts/config/prices.json
💤 Files with no reviewable changes: 1
  • crates/switchyard-desktop/prices.toml

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.

Walkthrough

The desktop installer now bundles pricing in JSON, migrates legacy TOML pricing, and validates pricing files. Generated configuration references the pricing file, and server launch paths use shared settings arguments. Tests cover pricing migration, invalid pricing, backups, and recovery.

Changes

Desktop Pricing Configuration

Layer / File(s) Summary
Pricing resources and server launch arguments
crates/switchyard-desktop/prices.toml, scripts/config/prices.json, crates/switchyard-desktop/src/install.rs, crates/switchyard-desktop/src/bin/switchyard-desktop-install.rs, crates/switchyard-desktop/src/install/windows.rs
The desktop installer uses bundled JSON pricing instead of the deleted TOML pricing file. Generated desktop configuration references prices_file and records a baseline model. Settings::server_args() supplies arguments to both launch paths and includes --pricing-file when the installed file exists.
Legacy pricing reconciliation
crates/switchyard-desktop/src/install.rs
Desktop settings reconciliation returns structured changes. When no pricing file exists, it extracts legacy rates and converts them to validated JSON. Conversion defaults cache_read to the input rate and sets cache_write to the input rate.
Installation, backups, and validation
crates/switchyard-desktop/src/install.rs, crates/switchyard-desktop/tests/desktop.rs
The installation plan includes the pricing file. Installation validates existing pricing and backs up desktop settings before applying rewrites. Tests cover pricing migration, bundled pricing, backups, invalid pricing rejection, and recovery assertions.

Priority: ➖ Normal

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

Merge Risk: ⚪ Minimal · up to ed9cb

The installer now creates a shared prices file and starts the server with it. No concrete merge-blocking risk was identified in the supplied changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.74% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check Passed The title clearly describes the main change: using bundled model prices by default during desktop installation.
Full details: Docstring Coverage

Explanation

Docstring coverage is 40.74% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the pricing JSON at dawn,
Then hops where legacy TOML once sat.
The server finds its pricing file,
While backups keep the old settings safe.
Bad rates are turned away at the gate,
And the rabbit rests beneath a config leaf.

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

Base automatically changed from emehtabuddin/desktop-installer-platforms to main October 21, 2026 03:11
@elyasmnvidian elyasmnvidian changed the title feat(desktop): install a shared prices.json and start the server with --pricing-file feat(desktop): install shared model prices Oct 21, 2026
@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/desktop-prices-file branch from ed9cb2d to a5efe3f Compare October 21, 2026 07:14
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.1

🚀 View preview at
https://NVIDIA-NeMo.github.io/Switchyard/pr-preview/pr-1049/

Built to branch gh-pages at 2026-10-21 17:30 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/desktop-prices-file branch from a5efe3f to e75c39d Compare October 21, 2026 16:31
@elyasmnvidian elyasmnvidian changed the title feat(desktop): install shared model prices feat(costs): use bundled model prices by default Oct 21, 2026
@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/desktop-prices-file branch from e75c39d to 01f2715 Compare October 21, 2026 16:53
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/desktop-prices-file branch from 01f2715 to a0531fb Compare October 21, 2026 17:29

@ayushag-nv ayushag-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we pull in cost from OpenRouter on the go instead of hardcoding ? It will be difficult to maintain

@bhuvan002
bhuvan002 self-requested a review October 21, 2026 18:44
@elyasmnvidian
elyasmnvidian merged commit 2cf1a7e into main Oct 21, 2026
20 checks passed
@elyasmnvidian
elyasmnvidian deleted the emehtabuddin/desktop-prices-file branch October 21, 2026 19:01
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