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

Context for managing AI provider configurations.

# `build_pricing_attrs`

```elixir
@spec build_pricing_attrs(map(), boolean()) :: map()
```

Builds the `"pricing"` key in a params map from raw form string inputs.

When `custom_pricing_enabled` is `true`, parses `"pricing_input"` and
`"pricing_output"` from `params` into numeric rates and sets `"pricing"`.
Invalid strings are forwarded as-is so changeset validation surfaces the
error. When disabled, `"pricing"` is set to `nil`.

# `change_provider`

```elixir
@spec change_provider(Aludel.Providers.Provider.t(), map()) :: Ecto.Changeset.t()
```

Returns a changeset for tracking provider changes.

# `create_provider`

```elixir
@spec create_provider(map()) ::
  {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}
```

Creates a new provider.

# `default_pricing`

```elixir
@spec default_pricing(atom() | binary() | nil, String.t() | nil) ::
  %{input: float(), output: float()} | nil
```

Resolves the LLMDB default pricing for a given provider atom and model string.

Returns `nil` when either argument is nil/empty or when no pricing data is found.

# `delete_provider`

```elixir
@spec delete_provider(Aludel.Providers.Provider.t()) ::
  {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}
```

Deletes a provider.

# `fetch_model_groups`

```elixir
@spec fetch_model_groups(nil | binary() | atom()) :: %{
  active: [map()],
  deprecated: [map()]
}
```

Fetches models grouped into active and deprecated sets.

# `fetch_models`

```elixir
@spec fetch_models(nil | binary() | atom()) :: [map()]
```

Fetches available models for a given provider type.

# `get_provider!`

```elixir
@spec get_provider!(binary()) :: Aludel.Providers.Provider.t()
```

Gets a provider by ID, raising if not found.

# `list_providers`

```elixir
@spec list_providers() :: [Aludel.Providers.Provider.t()]
```

Lists all providers in the system.

# `pricing_form_attrs`

```elixir
@spec pricing_form_attrs(Aludel.Providers.Provider.t()) :: %{
  custom_pricing_enabled: boolean(),
  pricing_input: String.t(),
  pricing_output: String.t()
}
```

Extracts pricing-related virtual field values from a persisted provider.

Returns a map suitable for merging into changeset attrs or socket assigns
when re-hydrating the provider form on edit.

# `update_provider`

```elixir
@spec update_provider(Aludel.Providers.Provider.t(), map()) ::
  {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}
```

Updates an existing provider.

---

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