Arcana::AI::Pricing
What calls cost at the providers' list prices, from the usage they report and a table of rates.
case cost = response.cost in Pricing::Cost then ledger.record(cost.total, cost.rates) in Pricing::Unpriced then log.warn(cost.detail) end
A Cost is what the provider charges for that usage at the rates in
the table, not an estimate: rates are looked up by the model the
provider says answered, at the time of the call, and nothing is
guessed. When something can't be known (a model the table doesn't
have, no usage reported, a tier or region it has no rates for), the
answer is Unpriced, with the reason. Account-level terms (free
allowances, credits, negotiated discounts, taxes) are outside a
call's price; reconciling with the provider's bill is a separate step.
The built-in table (Table.default) is pricing/rates.yml, kept to
the providers' published prices. Services it doesn't cover, or other
terms, go in a table of your own, merged over it:
rates = Pricing::Table.default.merge(Pricing::Table.from_yaml(File.read("rates.yml"))) response.cost(table: rates)