Skip to content

feat(pricing): dynamic provider prices with provenance and cache policy - #28

Merged
daimonbot merged 4 commits into
mainfrom
feat/dynamic-pricing
Oct 24, 2026
Merged

daimonbot merged 4 commits into
mainfrom
feat/dynamic-pricing

Conversation

@daimonbot

@daimonbot daimonbot commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Problem and result

Models missing from the old hardcoded tables appeared to cost $0 and were hidden by the minimum-cost filter. Atlas now resolves maintained catalogues at runtime, calculates an estimated API list-price cost for each call's model, and exposes unknown or incomplete prices as n/a or a lower bound.

Closes #20. Historical pricing is deferred to #31.

Agreed scope

The operator selected current-catalogue estimates for both recent and older sessions. Comparing old sessions at today's model prices is intentional. A reproducible historical ledger, effective dates, and invoice/subscription reconciliation are outside this PR. This is the selected alternative to #26; the two implementations should not be merged together.

Implementation

  • Synchronous lookup: local override > LiteLLM > OpenRouter. Exact model identities are checked before date-stripped aliases; no nearest-version guessing.
  • Input, output, cache reads, and 5-minute/1-hour cache writes are calculated separately where published. Missing classes make the estimate partial.
  • Refresh in the server's index worker, plus a bounded background refresh for CLI commands. Cache TTL 24 hours; retry after failure 1 hour. Offline mode and the small bundled fallback remain available. Delisted models retain their last known price.
  • Source URL, matched model, fetch time, content hash, currency, and applied rates are included in provenance.
  • Unpriced usage stays visible through filtering, dashboard totals, breakdowns, session views, CLI output, and HTML exports.
  • Session changes and local override edits invalidate indexed prices. Concurrent cache writers preserve newer prices and each other's model entries.
  • The CLI now calls the provider registry with session refs, fixing the existing path/ref crash so the pricing paths can actually be used.

Validation

  • npm run typecheck and npm run build pass.
  • The first verification run passed all 28 tests, none skipped, including browser navigation, unknown-price presentation, and standalone HTML export. A follow-up regression test covers sessions whose usage records are unavailable.
  • A live refresh of both catalogues succeeded and resolved Sonnet 4.6, Sonnet 4.5, Opus 5.5, GPT-4o, and GPT-6.1 Sol.
  • Regression coverage includes live worker updates, override repricing, concurrent refresh order, unknown/partial filtering and totals, CLI output, browser detail/call views, and standalone export.
  • npm run bench: 50,000 sessions, 100 returned rows, approximately 0.3 seconds locally and 0.18 seconds in CI. Fixed the test and benchmark date ranges so September fixtures do not expire out of the default 30-day window.

Local real-session verification

  • Tested recent and older real Claude and Codex sessions, including a Codex session that switched models. All samples with recorded usage received nonzero computed estimates.
  • Started the local HTTP server with two real Claude transcripts: list/detail amounts agreed; CLI list and standalone export succeeded.
  • The oldest sampled Codex thread had no token records. Fixed its presentation to show n/a rather than a zero estimate; added regression coverage.

Limits

These are approximate API list-price estimates, not actual subscription charges. Third-party catalogues can lag or contain errors; local overrides take precedence. Long-context, batch/priority tiers, and historical promotional windows are not modeled. Missing rates remain explicit.

Price models from a runtime catalogue (LiteLLM, then OpenRouter) instead of
a hardcoded table: on-disk cache with TTL, bundled offline snapshot, local
overrides, name normalisation across harnesses, per-price provenance, and an
explicit unknown state that the minimum-cost filter no longer hides.
…cher provenance

- try the exact (prefix-normalised) id in every source before the date-stripped one
- session view reads flatten() rows correctly and shows n/a / lower bound for
  unknown or partial usage in tables, breakdowns, flow and per-call costs
- treat unpublished token classes like unknown models in the cost filter
- merge cache writes under a lock so concurrent refreshes and failures never drop entries
- CLI no longer waits for the network before discovery; sources refresh in parallel
- provenance carries rates, currency and a content-hash source version; calls carry a confidence
@daimonbot
daimonbot merged commit a6af986 into main Oct 24, 2026
1 check passed
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.

feat: dynamic provider pricing with provenance and cache policy

1 participant