ExAgent. CostGuard
(ExAgent v2.1.0)
View Source
Helpers for turning token usage into an estimated cost, used together with
the max_budget_cents field of ExAgent.UsageLimits.
ExAgent does not ship a pricing table (model prices change constantly and
vary by vendor). You bring the prices that matter to you as a map and
CostGuard.estimator/1 builds the (usage -> cents) function you pass to
ExAgent.run/3 via the :estimate_cost option.
Example
pricing = ExAgent.CostGuard.estimator(%{
input_per_1k_cents: 250,
output_per_1k_cents: 1000
})
ExAgent.run(agent, "go", estimate_cost: pricing)
Summary
Functions
Evaluate legacy homogeneous or model-aware pricing without losing unknown/error states.
Build a cost estimator (Usage.t() -> fractional cents) from a pricing map.
Types
Functions
Evaluate legacy homogeneous or model-aware pricing without losing unknown/error states.
@spec estimator(pricing()) :: (ExAgent.Message.Usage.t() -> non_neg_integer() | float() | :unknown)
Build a cost estimator (Usage.t() -> fractional cents) from a pricing map.
Prices are per 1000 tokens, in cents (250 means $2.50 per 1K,
or $2500 per 1M tokens). Fractions are preserved rather than truncating every
small request to zero. Missing rates remain unknown when their token direction
is used; they do not imply a free provider.
This is a flat input/output approximation, without cache discounts or adding
reasoning subsets twice. Supply a model-aware callback for differentiated prices.