Skip to main content
Use traces to understand what ran, evaluations to check whether it was correct, and cost accounting to estimate reported usage. These answer different questions. The quality-gate project provides a complete runnable application that retains reports and JSONL traces.

Observe one run and estimate its cost

Set cost: true and attach the observer once. Read usage and cost from each run result. Install matching @agentium/core, @agentium/observability, and openai, then set OPENAI_API_KEY.
Expect a console trace and a return value with reported tokens, the cost assessment, and metrics. Default tracing excludes prompt, tool, and output content. A null total means the price is incomplete. knownSubtotal contains only the charges that Agentium could price.

Supply matching prices

A PricingCatalog contains dated rules for the billing provider, exact model ID, API, meter, currency, and billing context. Each rule states its rate unit. A rate of "10" per "1000000" tokens needs no conversion to a per-thousand number. Use separate rules for ordinary input, cache reads, cache writes, and output. Add cache lifetime, service tier, region, or context bands when the tariff requires them. See the complete four-charge example and pricing types. A requested Fast, Ultrafast, or Pro mode is evidence about the request. The response and provider contract determine the billed tier and model. Do not add a multiplier to a mode name without a matching price rule.

Add a budget

Set the budget once in the Agent configuration. The shorthand below uses USD thresholds:
Threshold checks use recorded costs before the next request. For concurrent workers, use reservations with a conservative bound and a shared accounting store. Neither mode can retract a request the provider already accepted. Model output limits and bounded tool rounds remain useful. Use stable tenant, user, and session IDs. Keep the accounting ledger for the period required by your application. The default in-memory store does not survive a process restart. See cost budgets for unknown costs, reservations, and failure handling.

Choose an evidence destination

Delivery through a bounded exporter is not an authoritative audit ledger. Flush owned telemetry after active runs and Agent cleanup settle; the host owns shutdown of borrowed exporters or SDK providers according to their contract.

More patterns

Use exporter selection for all destinations, capture settings for bounded content capture, evaluation patterns for answer quality, and operations for limits and drain.