Resolve a provider specification into a full provider config.
Accepts:
- Atoms (e.g.
:openai,:anthropic) — mapped to provider modules - Maps with
:adapterand:base_url— used as-is - Modules implementing
LLM.Providerbehaviour - Tuples
{module, opts}— module with runtime options (e.g.,api_key)
Examples
LLM.Provider.Resolver.resolve(:openai)
#=> %{adapter: LLM.Adapter.OpenAI, base_url: "https://api.openai.com/v1", ...}
LLM.Provider.Resolver.resolve(LLM.Provider.Anthropic)
#=> %{adapter: LLM.Adapter.Anthropic, base_url: "https://api.anthropic.com", ...}
LLM.Provider.Resolver.resolve({LLM.Provider.OpenAI, api_key: "sk-..."})
#=> %{adapter: LLM.Adapter.OpenAI, base_url: "https://api.openai.com/v1", api_key: "sk-..."}
LLM.Provider.Resolver.resolve(%{
adapter: LLM.Adapter.OpenAI,
base_url: "http://localhost:11434/v1"
})
#=> %{adapter: LLM.Adapter.OpenAI, base_url: "http://localhost:11434/v1", api_key: nil}
Summary
Functions
@spec list_providers() :: [atom()]
List all available provider preset atoms.
Returns the list of atoms that can be passed as a :provider option:
LLM.Provider.Resolver.list_providers()
#=> [:openai, :openai_responses, :anthropic, :gemini, :openrouter]
@spec pricing(atom() | module(), String.t()) :: LLM.Usage.pricing() | nil
Get pricing for a model from a provider.
Returns the pricing map if the provider implements pricing/1 and has
pricing data for the model, or nil if unknown.
Pricing resolution order:
- Call-site
:pricingoption (passed directly) - Provider module's
pricing/1callback nil(no pricing available)
Examples
LLM.Provider.Resolver.pricing(LLM.Provider.OpenAI, "gpt-4o")
#=> %{input: 2.50, output: 10.00, ...}
LLM.Provider.Resolver.pricing(LLM.Provider.OpenRouter, "gpt-4o")
#=> nil