Per-Call Metrics
Every model call returns usage metrics:Agent Run Metrics
Agent runs aggregate metrics across all model calls in the run (including tool execution loops):UsageTracker (Recommended)
The simplest way to track costs across runs. Enable withusage=True on the Agent constructor:
UsageSnapshot provides:
Snapshots support addition (
a + b) and serialization (to_dict()).
Tracking Across Multiple Runs (Manual)
For more control, useMetrics addition to aggregate costs across a session or batch:
sum():
MetricsMiddleware
TheMetricsMiddleware tracks aggregate stats across all runs for an agent:
Cost Breakdown
TheMetrics class tracks all cost dimensions:
Pricing Registry
Definable includes a built-in pricing registry (model_pricing.json) with rates for all supported models. Cost is calculated automatically based on the model and token counts.
Prices are defined per million tokens:
Serializing Metrics
Export metrics for logging, dashboards, or billing systems:None fields are excluded automatically for clean output.