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. Seecrate::tracing.TurnEvent::Usage/TurnEvent::ChildUsage: live during a turn, one event per LLM iteration.Usageis the parent’s own model call;ChildUsagecarriessession_id+sourceso a UI can group child traffic (e.g. by subagent). Right for live counters.TurnResult::usage/TurnResult::children_usage: per-turn snapshot at completion.usageis parent-only;children_usageis a per-(source, model)breakdown.TurnResult::total_usagesums both. Right for “what did this message cost.”SessionUsageReport(session.usage_report()): aggregate across the whole session, broken down bysource×model. Right for dashboards and “session so far.”
Modules§
- sources
- Well-known source labels used by the runtime and first-party plugins.
Structs§
- Session
Usage Report - Token
Ledger Entry - A single row in the token cost ledger. One per unique
(source, model)pair — accumulated, not per-call. - Token
Usage - Token usage statistics from an LLM call.
- Usage
Report Row - Usage
Totals