module

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)

Constants

BUILT_IN = {{ read_file("/tmp/tmp.lgpOii/src/src/arcana-ai/pricing/rates.yml") }}
MILLION = BigDecimal.new(1000000)
THOUSAND = BigDecimal.new(1000)

Class methods

cost(provider : String, model : String, usage : Usage | Nil, at : Time = Time.utc, table : Table = Table.default) : Cost | Unpriced

Price usage of model from provider (the names responses carry), at the rates in force at at.

Source
cost!(provider : String, model : String, usage : Usage | Nil, at : Time = Time.utc, table : Table = Table.default) : Cost

As cost, raising UnpricedError when the call can't be priced.

Source

Nested types