Skip to content

Feature request: per-model token usage and cost statistics #320

Description

@ffftttft

Problem

pi-web already has the two raw ingredients for cost tracking, but nothing that aggregates them:

What's missing is the aggregation layer: a view that answers "how much have I spent per model this week/month, and where?"

Proposal

A usage statistics page/panel that aggregates across sessions:

  • Per model (provider/model id): total input / output / cache-read / cache-write tokens, message count, session count.
  • Estimated cost: tokens × the configured pricing preset (from the models.dev catalog or user-overridden prices in models.json); clearly marked as an estimate, hidden or marked N/A for models without pricing info.
  • Time range filtering: today / 7d / 30d / all.
  • Data source: scan session .jsonl files (same read path as the session list) and aggregate assistant message usage blocks — no changes to the agent runtime needed. Results can be cached server-side and invalidated on session file mtime changes.

Nice-to-haves (could be follow-ups): per-project breakdown, CSV export, daily trend chart.

Notes

  • Happy to contribute a PR for this. I'd start with a read-only /api/usage endpoint + a stats panel, no schema changes to session files.
  • If maintainers would rather see this as an extension/plugin instead of core UI, let me know and I'll scope it that way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions