Resolves pricing for a given provider and model.
Uses LLMDB's per-model cost data as the default source of truth, with support for user-defined custom pricing overrides.
Rates are always expressed per 1 million tokens.
LLMDB model data is indexed once into :persistent_term on first use,
making all subsequent lookups O(1).
Summary
Functions
Formats pricing for human-readable display.
Returns the effective pricing for a provider/model combination.
Functions
Formats pricing for human-readable display.
Examples
iex> Aludel.Providers.Pricing.format_pricing(%{input: 3.0, output: 15.0})
"$3.00 / $15.00 per 1M tokens"
iex> Aludel.Providers.Pricing.format_pricing(%{input: 0, output: 0})
"Free"
iex> Aludel.Providers.Pricing.format_pricing(nil)
"Unknown"
Returns the effective pricing for a provider/model combination.
Priority
- If
custom_pricingis a map withinputandoutputkeys, return it directly - Ollama models always resolve to free (
%{input: 0.0, output: 0.0}) since they run locally and use a different provider atom in LLMDB (:ollama_cloud) - LLMDB index (built once from
LLMDB.models(), cached in:persistent_term) — O(1) lookup - Returns
nilif no pricing data is available
Parameters
provider- Provider atom (e.g.,:openai,:anthropic)model- Model ID string (e.g.,"gpt-4o")custom_pricing- Optional map with:input/:outputor"input"/"output"keys
Returns
%{input: float, output: float}with rates per 1M tokensnilif no pricing data is available