LLM.Provider.Resolver (LLM v0.2.0)

Copy Markdown View Source

Resolve a provider specification into a full provider config.

Accepts:

  • Atoms (e.g. :openai, :anthropic) — mapped to provider modules
  • Maps with :adapter and :base_url — used as-is
  • Modules implementing LLM.Provider behaviour
  • 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

List all available provider preset atoms.

Get pricing for a model from a provider.

Functions

list_providers()

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

pricing(provider, model_id)

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

  1. Call-site :pricing option (passed directly)
  2. Provider module's pricing/1 callback
  3. 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

resolve(config)

@spec resolve(atom() | map() | module() | {module(), keyword()} | nil) ::
  LLM.Provider.config()