Usage CLI

Local token/cost usage reporting

Every time your agent runs with a session store, it records total_tokens and cost per session. praisonai usage reports those totals โ€” no config, no network.

bash
praisonai usage
Diagram

๐Ÿ’พ Sessions on disk

๐Ÿ“Š praisonai usage

โœ… Aggregate table

Quick Start

  1. Run the report

    Print the last 30 days, grouped by day.

    bash
    praisonai usage
  2. Group by model or project

    Switch the grouping dimension with --by.

    bash
    praisonai usage --by model
    praisonai usage --by project
  3. Window the results

    Limit the report to a time window with --days (0 = all history).

    bash
    praisonai usage --days 7
    praisonai usage --days 0
  4. Emit JSON

    Produce machine-readable output for scripts.

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

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


How It Works

The command reads the current-project and global default session stores, filters by time window, groups the rows, then renders a table or JSON.

Diagram

๐Ÿ’พ Current project store

๐Ÿ“ฅ Collect rows

๐Ÿ’พ Global default store

๐Ÿ—“ Filter by days

๐Ÿ“Š Group by day/model/project

โœ… Table or JSON

BehaviourDetail
Project bucketsWithout --project, rows keep their origin โ€” current and global show as separate buckets under --by project.
De-duplicationSessions with the same session_id in both stores are counted once.
Scan limitEach store is scanned up to 100,000 sessions.
Sort order--by day is chronological; --by model and --by project are highest-spend-first.
Empty statePrints No usage recorded yet when no rows and no errors.
ErrorsA missing or damaged store prints Usage may be incomplete: โ€ฆ (table) or fills the errors array (JSON) โ€” nothing is swallowed.
Cost sourceReads the pre-persisted cost field โ€” no re-pricing.

Options

OptionShortTypeDefaultDescription
--days-dint30Only include sessions updated in the last N days (0 = all)
--by-bstr"day"Group by: day, model, project, or tool
--project-pstrNoneRestrict to a specific project ID
--jsonโ€”boolFalseEmit machine-readable JSON

An invalid --by value prints --by must be one of: day, model, project, tool and exits with code 1.


Which --by should I pick?

Pick the grouping that answers your question.

Diagram

Yes

No

Yes

No

Yes

What do I want to know?

Spend over time?

–by day

Which model costs most?

–by model

–by project

Which tool is flaky or slow?

–by tool

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


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.


JSON Output

--json prints a stable shape for dashboards and pipelines.

json
{
  "by": "day",
  "days": 30,
  "project": null,
  "rows": [ { "key": "2026-07-19", "total_tokens": 1200, "cost": 0.0034 } ],
  "total_tokens": 1200,
  "cost": 0.0034,
  "errors": []
}

Table output shows cost to 4 decimal places ($0.0034); JSON rounds to 6.

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.


Common Patterns

Run a quick weekly review of spend by day.

bash
praisonai usage --days 7

Audit which model costs the most across all history.

bash
praisonai usage --by model --days 0

Feed a JSON report into a spreadsheet or dashboard.

bash
praisonai usage --json > usage.json

Spot flaky or slow tools.

bash
# 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)'

Best Practices

Enable a session store first

Rows only exist once agents run with a session store. Enable one with memory="history" or a session_id so praisonai usage has data to report.

Keep –days small for fast iteration

A short window (--days 7) scans fewer sessions and returns quicker during active development.

Use –json for scripting

Pipe --json into jq or a spreadsheet instead of parsing the table.

Remember –project scopes the read

Passing --project <id> reads only that project’s store โ€” the global bucket is skipped.

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