Skip to content

[Feature]: add provider/model estimated cost and cache metrics to Usage #1820

Description

@str0203

Area

Web Dashboard → Usage

Relationship to existing work

This is a focused follow-up to #1058.

Issue #1058 tracks calendar-day/custom-range filtering and daily model breakdown. This issue tracks the provider/model usage accounting that should be displayed for the selected timeframe. It should reuse the existing usage-summary/data path and pricing infrastructure rather than introduce a separate analytics system.

Goal

Give operators a practical local estimate of where tokens and estimated spend are going, and how effectively prompt caching is being used.

This is intentionally about local estimated usage cost, not official provider billing, account balances, invoices, or quota tracking.

Required breakdown

For the selected calendar day or date range, show provider-level and model-level rows containing, where available:

  • provider
  • model
  • request count
  • input tokens
  • output tokens
  • total tokens
  • cache-read input tokens
  • cache-creation input tokens
  • estimated cost in USD
  • usage/price coverage or an equivalent indication of data quality

Model rows must remain attributable to their provider. The provider view should support expanding into, or filtering by, its models.

Cache metrics

Where the upstream/provider reports sufficient counters, expose:

  • cache-read tokens
  • cache-creation tokens
  • cache hit rate
  • optionally, cache participation rate if that is more meaningful for a provider

The cache-hit-rate formula must be deterministic and documented. A reasonable default is:

cacheReadInputTokens / inputTokens

or, when uncached input is available:

cacheReadInputTokens / (cacheReadInputTokens + uncachedInputTokens)

If the necessary counters are unavailable, show unavailable/unknown, not 0%.

Estimated cost

  • Reuse the existing model/provider pricing and cost-estimation fields where possible.
  • Include cache-read and cache-creation pricing when configured and supported.
  • If a provider/model has no matching price, show the row as unpriced/unavailable instead of silently treating it as $0.
  • Keep the result clearly labeled as an estimate.

Daily drill-down

When a date range contains multiple days, users should be able to inspect the same provider/model/token/cache/cost breakdown for one individual calendar day, either by selecting a day in the existing Usage chart or through a daily detail table.

The implementation should compose with #1058's date filters and daily model view, but does not need to duplicate that UI.

Data-path requirements

  • Aggregate in the authoritative usage-summary/API layer.
  • Do not parse usage.jsonl directly in the frontend.
  • Do not reconstruct provider/model totals from chart pixels or unrelated UI state.
  • Preserve existing 7d/30d/available-history behavior and the date semantics defined by [Feature]: add single-day/custom date filtering and daily model metrics to Usage #1058.
  • Add deterministic tests for provider/model attribution, cache counters, cache-rate calculation, estimated pricing, and unavailable-data behavior.

Suggested delivery

This can be delivered in small independently testable slices:

  1. Normalize and expose provider/model cache and pricing fields in the usage-summary/API result.
  2. Add aggregation and regression tests.
  3. Add provider/model tables and estimated-cost columns.
  4. Add cache metrics and daily drill-down integration.

Acceptance criteria

  • A selected day or date range shows provider-level and model-level request/token totals.
  • Cache-read and cache-creation tokens are shown separately when available.
  • Cache hit rate is shown only when its inputs are available, using a documented formula.
  • Missing cache data is shown as unavailable/unknown, not as zero.
  • Estimated cost is shown per provider/model when price data is available.
  • Cache pricing is included when supported by the configured price data.
  • Unmatched prices are visibly unpriced/unavailable, not silently counted as $0.
  • A user can inspect the provider/model breakdown for an individual day within a multi-day selection.
  • Existing Usage ranges and [Feature]: add single-day/custom date filtering and daily model metrics to Usage #1058's date-boundary/API separation requirements remain intact.
  • Backend/API and frontend regression tests cover the new behavior.

Out of scope

  • Official provider invoices or billing APIs
  • Provider account balances or quota/reset tracking
  • A separate analytics database
  • Replacing the existing Usage workspace

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions