Skip to content

feat(pricing): add models.dev-backed tier-aware costs - #458

Merged
seakee merged 14 commits into
mainfrom
feat/models-dev-pricing-source
Jul 29, 2026
Merged

feat(pricing): add models.dev-backed tier-aware costs#458
seakee merged 14 commits into
mainfrom
feat/models-dev-pricing-source

Conversation

@seakee

@seakee seakee commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

Use models.dev as the preferred public model-price catalog with LiteLLM and OpenRouter fallbacks, bounded synchronization, and last-known-good retention.
Add context-tier and explicit Fast/Priority pricing across backend rollups, Dashboard, Monitoring, and frontend cost estimation.

Scope

  • Frontend panel
  • Manager Server
  • CPA panel mode
  • Full Docker mode
  • Native packages / release
  • Docs / Wiki
  • CI / build / tooling

Changes

  • Prefer models.dev during price synchronization while retaining LiteLLM and OpenRouter fallbacks, ETag reuse, source timeouts, and failure-safe preservation.
  • Parse, validate, persist, and display context tiers and experimental Fast/Priority service-tier prices with explicit-zero and inheritance semantics.
  • Classify usage by billing model, pricing model, context threshold, and effective service tier before calculating costs.
  • Add durable hourly and account pricing rollups, migration-aware rebuilds, transaction-consistent snapshots, and a background catch-up worker.
  • Apply tier-aware costs consistently to Dashboard, Monitoring, account history, and frontend usage calculations.
  • Document source priority, outage behavior, manual overrides, and supported tier semantics in English and Chinese.

User Impact

Cost estimates now distinguish models.dev context tiers and explicit Fast/Priority prices instead of collapsing all usage into one base rate. Existing prices remain available during source or network failures, and the Model Prices page exposes synchronized advanced rules. Provider billing and CPA routing are unchanged.

Compatibility / Runtime Notes

  • CPA panel mode: Uses the existing Manager Server APIs and panel bundle. Accurate tier selection requires CPA usage events to expose the effective service tier; missing metadata retains compatibility behavior.
  • Manager Server mode: Applies additive SQLite migrations and starts a background pricing-rollup worker. Price synchronization remains user-triggered.
  • Full Docker / native packages: No configuration changes are required. Outbound catalog access improves refreshes, while fallback sources and stored last-known-good prices cover outages.

Data / Security Notes

Adds SQLite tables for model-price tiers, pricing rollups, and rollup state. Existing base prices and raw usage remain local.
Catalog synchronization reads public pricing metadata only; it does not send usage events, management keys, credentials, or authentication files to models.dev.
No authentication, secret-storage, or CPA Management Key behavior changes.

Risk / Rollback

Risk level: Medium

Rollback notes:

Revert the PR or deploy the previous binary. The added SQLite tables are additive and may remain safely unused by older versions; existing base model-price rows are preserved. This changes local cost estimation only and does not affect provider billing or request routing.

Verification

  • Type check
  • Lint
  • Tests
  • Build
  • Manual UI check
  • Docs/link check
  • Not applicable, docs-only

Commands / evidence:

cd apps/manager-server && go test ./...
cd apps/manager-server && go test -race ./...
cd apps/manager-server && go vet ./...
npm run type-check
npm run lint
npm run test
npm run build
git diff --check

Frontend tests passed across 131 files and 1,213 tests. Repeated concurrency/race tests and pricing-rollup performance smoke benchmarks also passed. Manual UI and docs-link checks were not run; tier display and cost behavior are covered by automated tests.

Screenshots / Recordings

Not captured. The visible changes are data-dependent tier badges and a manual-replacement warning on the existing Model Prices page; automated model and UI tests cover their rendering decisions.

Docs

  • README / README_CN updated for user-visible capabilities
  • Matching docs manual and navigation updated
  • Demo fixtures, screenshots, and deep links reviewed
  • Release notes needed
  • Not needed — explanation included below

Docs decision:

README and both model-price manuals are updated. Existing Model Prices navigation and deep links remain unchanged. Release notes should be added in the next versioned release PR.

Related

N/A — no dedicated issue is linked.

seakee added 14 commits July 29, 2026 14:05
Use models.dev as the primary provider-scoped pricing catalog while retaining LiteLLM and OpenRouter fallbacks.

Add conflict-safe matching, ETag caching, indexed lookup, and conditional source fetching to reduce sync latency and network work.

Preserve manual confirmation for ambiguous pricing and avoid stale-cache fallback after source failures.
Update model price synchronization guidance in all supported locales.

Identify models.dev as the preferred source and LiteLLM and OpenRouter as fallbacks.

Keep the displayed behavior aligned with the Manager Server implementation without changing the frontend API contract.
Document source priority, provider-scoped identity handling, and conflict confirmation.

Clarify which models.dev cost fields are currently mapped into billing rules.

Note that tiers, Fast Mode, and reasoning metadata remain available but are not yet billed automatically.
Create SQLite tables for context and service-tier price rules and durable pricing rollups.

Add indexes, state initialization, and cascade coverage required by later repositories.

This schema-only change leaves application behavior unchanged until subsequent commits.
Extend model prices with normalized context and service-tier rules.

Persist, validate, and reload those rules transactionally through the model-price repository.

This establishes the price-book contract used by synchronization and cost calculation.
Classify usage by resolved pricing model, context threshold, and effective service tier.

Apply explicit context and service-tier rates while preserving legacy long-context behavior.

Add query-plan and cost regression coverage for mixed pricing bands.
Persist hourly and account pricing-band aggregates with migration-aware rebuild state.

Expose transaction-consistent snapshots and block price mutations during multi-query reads.

This keeps analytics fast while preserving a coherent price book during concurrent synchronization.
Parse context and Priority/Fast pricing rules from models.dev and notify rollup refreshes.

Bound source latency, retain valid ETag data, reject unusable catalogs, and preserve failed-source prices.

This keeps models.dev preferred without losing last-known-good pricing during outages.
Merge pricing-band rollups with pending raw usage in the shared hourly reader.

Preserve core usage metrics while exposing classified rows to cost-aware consumers.

This centralizes the optimized data path used by dashboard and monitoring services.
Start a pricing rollup worker and wake it after usage, migration, and price changes.

Integrate bounded catch-up and failure recording into the collector fanout.

This keeps pricing aggregates current without blocking request processing.
Use consistent price snapshots and classified rollups when calculating dashboard costs.

Handle Priority/Fast, Flex/Batch, and long-context bands without collapsing mixed aggregates.

Add correctness and performance coverage for dashboard refresh paths.
Price monitoring timelines, model totals, and account history from classified pricing bands.

Use snapshot-safe price reads and durable account rollups for large histories.

Add regression and benchmark coverage for mixed service tiers and context lengths.
Display synchronized context and service-tier rules and warn when manual prices replace them.

Calculate mixed Priority/Fast and long-context usage consistently with the backend.

Update API types, tests, styling, and all supported locales.
Document models.dev context and service-tier pricing rules in both manuals.

Explain last-known-good fallback behavior and how manual replacement clears synchronized rules.

Clarify Priority/Fast, Flex/Batch, and long-context cost semantics.
@seakee
seakee merged commit 08874e6 into main Jul 29, 2026
8 checks passed
@seakee
seakee deleted the feat/models-dev-pricing-source branch July 29, 2026 15:44
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