Skip to content

UsageReport

Category: Core

Source: usage_report.dart

Aggregator + data model for per-role token-usage breakdowns.

Reads persisted usage JSONL rows (written by [SessionManager.recordUsage]) and folds them into a [UsageReport] keyed by role. Used by the CLI's /usage slash command, the ACP session/usage_summary endpoint, and session-resume headers.

Classes

UsageReportRow

One row in the per-role breakdown table.

Constructor

dart
const UsageReportRow({
    required this.role,
    required this.calls,
    required this.input,
    required this.output,
    required this.cacheRead,
    required this.cacheWrite,
  })

Properties

PropertyTypeDescription
roleString
callsint
inputint
outputint
cacheReadint
cacheWriteint
totalTokensint get
totalTokensint get

UsageReport

Aggregated breakdown of a session's token usage.

Constructor

dart
const UsageReport({this.modelLabel, this.sessionId, required this.rows})

Properties

PropertyTypeDescription
modelLabelString?
sessionIdString?
rowsList<UsageReportRow>
totalCallsint get
totalInputint get
totalOutputint get
totalCacheReadint get
totalCacheWriteint get
totalTokensint get
totalCallsint get
totalInputint get
totalOutputint get
totalCacheReadint get
totalCacheWriteint get
totalTokensint get
cacheHitRatedouble? getCache hit rate across input tokens that the model saw — uncached input plus cache reads. Returns null when no LLM call has been recorded (avoids a misleading 0%).

Functions

`UsageReport buildUsageReport({

required Iterable<Map<String, dynamic>> usageEvents, String? modelLabel, String? sessionId, })`

Builds a [UsageReport] from persisted usage rows in conversation.jsonl. Unknown roles are surfaced as their own row so the report stays truthful even if a future surface adds new roles.

Released under the MIT License.