Cost Tracking
TheCostTracker tracks token usage and costs across agent runs. It supports budget enforcement, per-model pricing, detailed cost breakdowns by category, and per-agent/model/user summaries.
Quick Start
Token Types Tracked
TheCostTracker captures all token types returned by the API:
| Token Type | Field | Description |
|---|---|---|
| Input | promptTokens | Tokens in the prompt / input |
| Output | completionTokens | Tokens generated in the response |
| Reasoning | reasoningTokens | Tokens used for chain-of-thought (o1, o3) |
| Cached | cachedTokens | Prompt tokens served from API cache |
| Audio Input | audioInputTokens | Tokens from audio input (Realtime API) |
| Audio Output | audioOutputTokens | Tokens for audio output (Realtime API) |
getSummary() method aggregates totals across all tracked dimensions.
Raw Provider Metrics
EveryRunOutput.usage object includes a providerMetrics field containing the raw, unmodified usage data returned by the provider API. This gives full transparency without any normalization loss:
providerMetrics by provider:
Cost Breakdown
Each cost entry includes a 6-category breakdown:Built-in Pricing
Pricing is included for 50+ models:| Model | Prompt / 1K | Completion / 1K |
|---|---|---|
| gpt-4o | $0.0025 | $0.01 |
| gpt-4o-mini | $0.00015 | $0.0006 |
| claude-3.5-sonnet | $0.003 | $0.015 |
| gemini-2.0-flash | $0.0001 | $0.0004 |
Budget Enforcement
Budgets are checked before each LLM call and mid-run during tool-calling loops:Works Across All Agent Types
The sameCostTracker instance can be shared across different agent types:
Cost Summary
Events
| Event | Payload |
|---|---|
cost.tracked | { runId, agentName, modelId, usage, cost } |
cost.budget.exceeded | { runId, agentName, budget, current, limit } |
Subscribing to Cost Events
Listen for cost events to build dashboards, alerts, or analytics:Per-Agent and Per-Model Breakdown
Custom Pricing for Non-Built-in Models
Budget Enforcement in Practice
onBudgetExceeded: "warn", the run continues but emits a cost.budget.exceeded event instead of throwing.
Token Accuracy
RadarOS verifies 100% accuracy betweenCostTracker recorded tokens and raw API response tokens across all scenarios — simple completion, tool calling, multi-turn memory, and prompt caching. See benchmarks for detailed validation results.
Cross-References
- Agent Overview —
costTrackerin AgentConfig - Voice Agents —
costTrackerin VoiceAgentConfig - Browser Agents —
costTrackerin BrowserAgentConfig - Cost Auto-Stop — Mid-run budget enforcement
- Observability — Track costs alongside traces and metrics