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):Tracking Across Multiple Runs
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:
| Field | Description |
|---|---|
input_tokens | Tokens in the prompt |
output_tokens | Tokens generated |
cache_read_tokens | Tokens served from provider cache |
cache_write_tokens | Tokens written to provider cache |
reasoning_tokens | Tokens used for chain-of-thought |
audio_input_tokens | Audio input tokens |
audio_output_tokens | Audio output tokens |
cost | Total estimated cost in USD |
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.