Mimir.Pricing (Mimir v0.1.0)

Copy Markdown View Source

Token usage -> integer microdollar cost.

Lookup order for a "provider:model_id" key:

  1. Config table (:mimir, :pricing) keyed "provider:model_id" — wins when present.
  2. Vendored LiteLLM pricing DB fallback (loaded once, memoized in :persistent_term):
    • try bare model_id key in the DB
    • then "<provider>/<model_id>"
  3. 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

usage()

@type usage() :: %{
  optional(:input_tokens) => non_neg_integer(),
  optional(:output_tokens) => non_neg_integer()
}

Functions

cost_microdollars(model, usage)

@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.