Skip to main content

Module usage

Module usage 

Source
Expand description

Token usage tracking surfaces.

Four channels, finest granularity to coarsest:

  • TraceSink: every provider call across every session in the runtime. Right for billing, audit, off-line analysis. Heavier than necessary if you only want totals. See crate::tracing.
  • TurnEvent::Usage / TurnEvent::ChildUsage: live during a turn, one event per LLM iteration. Usage is the parent’s own model call; ChildUsage carries session_id + source so a UI can group child traffic (e.g. by subagent). Right for live counters.
  • TurnResult::usage / TurnResult::children_usage: per-turn snapshot at completion. usage is parent-only; children_usage is a per-(source, model) breakdown. TurnResult::total_usage sums both. Right for “what did this message cost.”
  • SessionUsageReport (session.usage_report()): aggregate across the whole session, broken down by source × model. Right for dashboards and “session so far.”

Modules§

sources
Well-known source labels used by the runtime and first-party plugins.

Structs§

SessionUsageReport
TokenLedgerEntry
A single row in the token cost ledger. One per unique (source, model) pair — accumulated, not per-call.
TokenUsage
Token usage statistics from an LLM call.
UsageReportRow
UsageTotals

Functions§

diff_token_ledger
diff_usage_reports