Token usage -> integer microdollar cost.
Lookup order for a "provider:model_id" key:
- Config table (
:mimir, :pricing) keyed"provider:model_id"— wins when present. - Vendored LiteLLM pricing DB fallback (loaded once, memoized in
:persistent_term):- try bare
model_idkey in the DB - then
"<provider>/<model_id>"
- try bare
- Miss → zero (never crashes metering).
Price table (:mimir, :pricing) values are %{input: µ$_per_million, output: µ$_per_million}.
The vendored DB stores the same shape after converting LiteLLM's USD/token floats at load time:
round(cost * 1.0e12) → integer µ$/M tokens. Integer math only on the hot path.
Refresh the vendored DB with mix mimir.pricing.refresh. The :mimir, :pricing_db_path
config key overrides the default priv path (useful in tests).
Summary
Functions
Cost of usage against model's rate, in integer microdollars. Looks up
the rate via the lookup order documented above; an unpriced model costs 0.
Types
@type usage() :: %{ optional(:input_tokens) => non_neg_integer(), optional(:output_tokens) => non_neg_integer() }
Functions
@spec cost_microdollars(String.t(), usage()) :: non_neg_integer()
Cost of usage against model's rate, in integer microdollars. Looks up
the rate via the lookup order documented above; an unpriced model costs 0.