# `Nous.Eval.Scorers.MaxCost`
[🔗](https://github.com/nyo16/nous/blob/v0.21.1/lib/nous/eval/scorers/max_cost.ex#L1)

Passes when the sample's model spend is at most `:max_usd`.

    {Nous.Eval.Scorers.MaxCost, max_usd: 0.02, required: false, weight: 0}

Cost is priced with `Nous.Usage.cost/2` (rates from `Nous.Usage.Pricing`).
By default every completed model request in the trace (the whole run tree,
including sub-agents) is priced with the model that actually answered it,
so fallbacks and sub-agents on other models are billed correctly. With
`:model`, the sample's summed `usage` is priced at that one model's rates
instead.

A model without a known price is a scorer error, never a pass: a wrong
price is worse than none. Declare it track-only (`required: false,
weight: 0`) unless the budget is a hard requirement.

## Options

  * `:max_usd` - the limit in US dollars (required)
  * `:model` - `"provider:model"` (or a `Nous.Model`) to price the summed
    usage with; must have a known price (checked in `init/1`)

On a truncated trace a cost within budget is a `:missing_trace` error (the
missing requests would add to it). `details` holds `cost_usd` and, when
priced from the trace, `by_model` (`"provider:model" => usd`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
