Usage

Zero-config local token and cost reporting across all your sessions

See what you’ve spent — no dashboard, no API key, no setup. praisonai usage reads the token and cost totals PraisonAI already saves per session and rolls them up by day, model, or project — or reports per-tool reliability with --by tool.

Diagram

praisonai usage

📂 Session Store

🔎 Filter –days –project

📊 Group –by day/model/project

✅ Table or JSON

Quick Start

  1. See your spend

    Run one line to see the last 30 days grouped by day.

    bash
    praisonai usage
                  Usage
    ┏━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
    ┃ Day        ┃ Tokens  ┃ Cost    ┃
    ┡━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
    │ 2026-07-19 │ 1,240   │ $0.0140 │
    │ 2026-07-20 │ 3,980   │ $0.0320 │
    │ Total      │ 5,220   │ $0.0460 │
    └────────────┴─────────┴─────────┘
  2. Group differently

    Switch the grouping to see spend by model or by project.

    bash
    praisonai usage --by model
  3. Group by project (current vs global stores)
    bash
    praisonai usage --by project
  4. Last 7 days only
    bash
    praisonai usage --days 7
  5. A single project
    bash
    praisonai usage --project my-app
  6. Get JSON for scripts

    Add --json for machine-readable output you can pipe to jq.

    bash
    praisonai usage --json
  7. See per-tool reliability
    bash
    praisonai usage --by tool

    Reports calls, success rate, average latency, and the last error for each tool used.


Choose Your Grouping

Pick the --by value that matches the question you’re asking.

Diagram

What are you trying to see?

Spend over time

Which model costs most

Which project costs most

Which tool is flaky or slow

praisonai usage –by day

praisonai usage –by model

praisonai usage –by project

praisonai usage –by tool

tool sorts by most-called first, so your busiest (or busiest-failing) tool rises to the top.


How It Works

praisonai usage reads the same session files that praisonai session list shows — nothing new is written, no external service is contacted.

Diagram
sequenceDiagram
    participant User
    participant CLI as praisonai usage
    participant Proj as Current-project store
    participant Glob as Global default store

    User->>CLI: praisonai usage --by model --days 7
    CLI->>Proj: list_sessions()
    Proj-->>CLI: sessions (total_tokens, cost, model, updated_at)
    CLI->>Glob: list_sessions()
    Glob-->>CLI: sessions
    CLI->>CLI: filter by --days, de-dup, group by --by
    CLI-->>User: table (or JSON if --json)

    classDef user fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef cli fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef store fill:#10B981,stroke:#7C90A0,color:#fff

    class User user
    class CLI cli
    class Proj,Glob store
SourceWhat it contributes
Current-project session storeSessions from the project you’re in — labelled current under --by project.
Global default session storeSessions from the global store — labelled global under --by project.
--project <id>Restricts to exactly that project’s store; its own ID becomes the sole project label.

When --project is omitted, both stores are scanned separately and session ids shared across them are de-duplicated (the current-project store wins). Each store is scanned up to 100,000 sessions to keep memory predictable — realistic stores are never truncated.

BehaviourDetail
Time window--days filters on updated_at; values without a timezone are treated as UTC
Sorting--by day is chronological; --by model / --by project sort by highest tokens first
Grouping keysUnknown model → unknown; unparseable date → unknown; empty project → current
Total rowThe table always appends a Total row
Zero valuesRender as -; tokens are comma-formatted; cost is $X.XXXX

Options

Every option is optional — praisonai usage with no flags reports the last 30 days by day.

OptionShortTypeDefaultDescription
--days-dint30Only include sessions updated in the last N days. 0 = no time filter (include all).
--by-bstr"day"Group by: day, model, project, or tool. Any other value exits with an error.
--project-pstrNoneRestrict to a specific project ID (reads only that project’s scoped store).
--jsonboolFalseEmit machine-readable JSON (also auto-enabled by the CLI’s global JSON output mode).

--by day sorts chronologically (ascending); --by model and --by project sort by tokens descending (highest spend first); --by tool sorts by call count descending, then alphabetically.

JSON output shape

--json emits a stable object you can pipe into dashboards or cron jobs.

bash
praisonai usage --by day --days 30 --json
json
{
  "by": "day",
  "days": 30,
  "project": null,
  "rows": [
    {"key": "2026-07-15", "total_tokens": 12340, "cost": 0.043},
    {"key": "2026-07-18", "total_tokens": 5220, "cost": 0.014}
  ],
  "total_tokens": 17560,
  "cost": 0.057,
  "errors": []
}

With --by tool, each row describes a tool instead of a spend bucket:

json
{
  "by": "tool",
  "days": 30,
  "project": null,
  "rows": [
    {
      "tool": "search",
      "calls": 3,
      "successes": 2,
      "errors": 1,
      "success_rate": 0.6667,
      "avg_ms": 200.0,
      "last_ms": 200.0,
      "last_error": "timeout"
    }
  ],
  "errors": []
}

Tool mode omits the top-level total_tokens / cost fields — it reports outcomes, not spend.

Empty output

  • Table: No usage recorded yet
  • JSON: {"rows": [], "total_tokens": 0, "cost": 0.0, ...}
  • --by tool table: No tool usage recorded yet

Store errors

A missing or damaged store is non-fatal. Table mode prints Usage may be incomplete: <reason> as a warning; JSON mode exposes the reasons under errors. The command still exits 0 and returns whatever it could read — a broken store is never silently reported as empty. An invalid --by value exits 1 with --by must be one of: day, model, project, tool.


Common Patterns

Practical one-liners for everyday reviews.

bash
# Weekly review by model
praisonai usage --days 7 --by model

# CI cost snapshot
praisonai usage --json | jq '.cost'

# Full history by project (no time filter)
praisonai usage --days 0 --by project

# Export 90 days to CSV
praisonai usage --days 90 --by day --json | jq '.rows[] | [.key, .total_tokens, .cost] | @csv' -r > usage.csv

# Spot flaky tools over the last week
praisonai usage --by tool --days 7

# Find the slowest tool across all history
praisonai usage --by tool --days 0 --json | jq '.rows | sort_by(-.avg_ms) | .[0]'

# Alert on tool failure rate in CI
praisonai usage --by tool --json | jq '.rows[] | select(.success_rate < 0.9)'

Grouping Modes

ModeSorts byUse it to
--by dayChronologicalSee a spend trend over time.
--by modelHighest spend firstFind which model costs the most.
--by projectHighest spend firstCompare spend across workspaces.
--by toolMost calls firstSpot flaky or slow tools.

Per-Tool Reliability

praisonai usage --by tool reports per-tool call counts, success rate, average and last latency, and the last error — read from the local session store, same as every other grouping.

Diagram

praisonai usage –by tool

🪝 AFTER_TOOL hook

📊 Per-tool tally

💾 Session metadata

✅ Tool report

                                 Tool usage
┏━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Tool       ┃ Calls ┃ Success ┃ Avg ms ┃ Last ms ┃ Last error ┃
┡━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━┩
│ search     │     3 │  66.7%  │   200  │   200   │ timeout    │
│ write_file │     1 │ 100.0%  │     5  │     5   │ -          │
└────────────┴───────┴─────────┴────────┴─────────┴────────────┘
ColumnMeaning
ToolTool name as the runtime saw it
CallsHow many times the tool was invoked
SuccessPercentage of calls that returned without an error
Avg msAverage execution time across all calls
Last msLatency of the most recent call
Last errorLast error message (truncated to 60 chars in the table, 500 in JSON)

Last ms and Last error are picked by when the tool itself last ran, not by when the session was last updated. If no tool calls are recorded, the command prints No tool usage recorded yet.


Best Practices

Find your most expensive models

Run praisonai usage --by model — models are sorted by highest token count first, so the biggest spenders appear at the top.

Report across all history

Use praisonai usage --days 0 to disable the time filter and aggregate every session on disk, not just the last 30 days. Use this sparingly on very large session directories, since it scans up to 100,000 records per store.

Feed usage into scripts

praisonai usage --json emits a stable shape (by, days, project, rows, total_tokens, cost, errors) that is safe to parse in CI or dashboards. The global JSON output mode auto-enables JSON, so scripts running under it get machine-readable output without passing --json explicitly.

Trust the numbers

Watch for Usage may be incomplete warnings. They mean a store could not be read fully — check filesystem permissions on the session store path and look for corrupt records. The totals shown exclude that store rather than silently reporting zero. In --json mode the same reasons appear in the errors array.

Attribute cost per workspace

Combine --project my-app with --by model to see which model drives spend inside one project.

bash
praisonai usage --project my-app --by model
Script budget checks

Pipe --json output to jq in CI to fail a build when spend crosses a threshold.

bash
praisonai usage --json | jq 'if .cost > 5 then error("over budget") else .cost end'
Missing cost? Check pricing coverage

Cost only appears for models present in the default pricing table. See Cost Tracking to add custom pricing.

Read current vs global buckets correctly

Without --project, --by project splits usage into a current bucket (this project’s store) and a global bucket (the default store). Shared session IDs appear once. Pass --project my-app to report a single project only.

Spot flaky or slow tools before users notice

Run praisonai usage --by tool --days 7 as part of your weekly review. Rows are sorted by call count first, so the busiest tool is on top — and the Success column immediately shows which ones are quietly failing. Pipe --json into jq in CI to fail a build when any tool drops below your target success rate.


Related