CostTracker records reported token usage and estimates cost from a model price table. Budget checks operate on recorded usage; they do not reserve provider credit or guarantee a run cannot exceed a spending threshold. Configure provider-side controls separately where needed.
The v4 bundled price table predates the refreshed GPT-6 example models. The examples below supply explicit text rates in USD per 1,000 tokens from the OpenAI catalog, checked October 4, 2026. Update the table when selecting another model or billing tier. Cached, audio, and other provider-specific rates may differ.
Quick Start
new CostTracker(config?)
Pass the instance as
costTracker on Agent. Tracked automatically on every run().
Instance methods
Token Types Tracked
TheCostTracker captures all token types returned by the API:
All token types are tracked per-message, per-run, and per-session. The
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:
Override or extend pricing:
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
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
Agentium 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