Smith::Pricing
Turns token counts into money.
The governing rule: a wrong cost figure is worse than no cost figure. A
model the table has never heard of prices as nil, which surfaces as
n/a — never as a plausible-looking guess. Rates go stale as vendors
change them, so every entry can be overridden from config.
Constants
PER_MILLION = 1000000.0
TABLE = {"anthropic/claude-fable-5" => Rates.new(input: 10.0, output: 50.0), "anthropic/claude-opus-5" => Rates.new(input: 5.0, output: 25.0), "anthropic/claude-opus-4-8" => Rates.new(input: 5.0, output: 25.0), "anthropic/claude-opus-4-7" => Rates.new(input: 5.0, output: 25.0), "anthropic/claude-opus-4-6" => Rates.new(input: 5.0, output: 25.0), "anthropic/claude-sonnet-5" => Rates.new(input: 3.0, output: 15.0), "anthropic/claude-sonnet-4-6" => Rates.new(input: 3.0, output: 15.0), "anthropic/claude-haiku-4-5" => Rates.new(input: 1.0, output: 5.0)}
Only models whose published rates are actually known. Everything else is
deliberately absent: n/a is the honest answer, and [pricing] is there
for anyone who knows better.
Class methods
cost(usage : LLM::Usage, rates : Rates) : Float64
Sourceestimate(usage : LLM::Usage, provider : String, model : String, overrides : Overrides | Nil = nil) : Float64 | Nil
nil means "no basis to say" — never zero-as-unknown, which would read as free.
format(cost : Float64 | Nil) : String
Sub-cent amounts are the common case for a single turn, so they get the extra digits rather than rounding to $0.00.
key_for(provider : String, model : String) : String
Sourcerates_for(provider : String, model : String, overrides : Overrides | Nil = nil) : Rates | Nil
Source