Skip to main content
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

The CostTracker 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

Every RunOutput.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:
Example providerMetrics by provider:

Cost Breakdown

Each cost entry includes a 6-category breakdown:
Access per-run or aggregated:

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:
See Cost Auto-Stop for mid-run enforcement details.

Works Across All Agent Types

The same CostTracker 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

If a model has no pricing entry (built-in or custom), the cost is recorded as $0 but token counts are still tracked.

Budget Enforcement in Practice

With onBudgetExceeded: "warn", the run continues but emits a cost.budget.exceeded event instead of throwing.

Token Accuracy

Agentium verifies 100% accuracy between CostTracker 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