# `Aludel.Providers.Pricing`
[🔗](https://github.com/ccarvalho-eng/aludel/blob/main/lib/aludel/providers/pricing.ex#L1)

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

# `format_pricing`

```elixir
@spec format_pricing(%{input: number(), output: number()} | nil) :: String.t()
```

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"

# `get_pricing`

```elixir
@spec get_pricing(atom(), String.t(), map() | nil) ::
  %{input: number(), output: number()} | nil
```

Returns the effective pricing for a provider/model combination.

## Priority

1. If `custom_pricing` is a map with `input` and `output` keys, return it directly
2. 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`)
3. LLMDB index (built once from `LLMDB.models()`, cached in `:persistent_term`) — O(1) lookup
4. Returns `nil` if 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`/`:output` or `"input"`/`"output"` keys

## Returns

  - `%{input: float, output: float}` with rates per 1M tokens
  - `nil` if no pricing data is available

---

*Consult [api-reference.md](api-reference.md) for complete listing*
