Skip to content

feat(pricing): sync reference model prices from models.dev - #565

Open
DemosHume wants to merge 1 commit into
SaladDay:mainfrom
DemosHume:feat/models-dev-pricing-sync
Open

DemosHume wants to merge 1 commit into
SaladDay:mainfrom
DemosHume:feat/models-dev-pricing-sync

Conversation

@DemosHume

Copy link
Copy Markdown

Models absent from the built-in price table require manual price entry before usage costs can be calculated. This adds an explicit pricing sync command to import reference text-model prices from models.dev.

cc-switch pricing sync --provider openai --model gpt-6.1-sol --dry-run
cc-switch pricing sync --provider openai --model gpt-6.1-sol --backfill
cc-switch pricing sync --provider anthropic --overwrite --json
  • Require a models.dev catalog provider; accept repeatable exact model IDs or select all supported text models for that provider.
  • Preserve existing prices and deletion markers by default; require --overwrite to replace or restore them. Import each selected batch atomically.
  • Preview without opening the database. Optionally backfill selected models using the existing missing-cost helper, without startup usage maintenance running before the import.
  • Prefer exact catalog IDs before normalized pricing fallbacks, including namespaced and mixed-case IDs.
  • Bound downloads to 30 seconds / 32 MiB, validate numeric prices, and reject unsupported explicit selections. No configured API credentials are sent to models.dev.

These are base USD-per-million reference prices, not actual provider bills. Context tiers and discounts are not represented. Sync is manual; this does not add background network traffic, schema changes, or TUI controls. English and Chinese usage documentation is included.

Validation (Linux, pinned Rust 1.91.1):

  • cargo fmt --check passed.
  • cargo test --locked pricing_sync --lib: 10 passed.
  • cargo test --locked services::usage_stats::tests --lib: 24 passed.
  • cargo test --locked --bin cc-switch update_and_completions_skip_startup_state: 1 passed.
  • Plain cargo clippy --locked is blocked by the existing zero-length range in src/cli/tui/ui/home_chart.rs:806 (BAR_AXIS_INSET_ROWS = 0, also present in the base). cargo clippy --locked -- -A clippy::reversed_empty_ranges passed with existing warnings.
  • Windows cargo +stable check --locked passed. Windows unit tests are blocked by existing unguarded std::os::unix imports in TUI tests, so the relevant tests were run on Linux instead.

Regression coverage includes local-price/deletion preservation, atomic rollback, optional cache-aware backfill, historical rows older than retention, exact-ID precedence, a database-free preview, and HTTP/JSON/size failures. Two independent review rounds completed with no remaining in-scope findings.

Existing limitation retained: the shared backfill helper selects eligible rows before starting its transaction, so concurrent independent backfills can race. This PR reuses that behavior; it does not redesign global backfill concurrency.

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.

1 participant