LlmCore.Provider.Registry (llm_core v0.3.0)

Copy Markdown View Source

In-memory accessors for provider definitions loaded from TOML configuration.

The registry reads provider metadata from LlmCore.Config.Store so callers can inspect capabilities, resolve modules, find providers by alias, and get fuzzy suggestions — all without touching disk.

Querying Providers

# All configured providers (keyed by id)
LlmCore.Provider.Registry.all()
#=> %{"anthropic" => %Definition{...}, "openai" => %Definition{...}, ...}

# Only available providers (enabled, API key present / binary found)
LlmCore.Provider.Registry.available()

# By exact id
{:ok, def} = LlmCore.Provider.Registry.fetch("anthropic")

# By implementing module
{:ok, def} = LlmCore.Provider.Registry.lookup_by_module(LlmCore.LLM.OpenAI)

# By alias (returns all matching)
defs = LlmCore.Provider.Registry.lookup_alias("claude")

# Fuzzy suggestions (Jaro distance)
LlmCore.Provider.Registry.suggest_alias("claud")
#=> ["claude"]

# Capable providers for requirements
LlmCore.Provider.Registry.suggest_capable(%{streaming: true, tool_use: true})
#=> [%{alias: "claude", provider: "anthropic", cost_tier: "premium", ...}]

Summary

Functions

Returns the map of all provider definitions keyed by provider id.

Returns only providers that are currently available (enabled and healthy).

Fetches a provider by id.

Fetches provider definitions whose alias list contains the given alias.

Finds a provider definition by the implementing module.

Suggests provider aliases that closely match the given term.

Suggests providers capable of meeting the given capability requirements. Returns metadata so callers can surface cost tiers/model availability.

Functions

all()

@spec all() :: %{optional(String.t()) => LlmCore.Provider.Definition.t()}

Returns the map of all provider definitions keyed by provider id.

available()

@spec available() :: [LlmCore.Provider.Definition.t()]

Returns only providers that are currently available (enabled and healthy).

fetch(id)

@spec fetch(String.t()) ::
  {:ok, LlmCore.Provider.Definition.t()} | {:error, :not_found}

Fetches a provider by id.

lookup_alias(alias)

@spec lookup_alias(String.t()) :: [LlmCore.Provider.Definition.t()]

Fetches provider definitions whose alias list contains the given alias.

lookup_by_module(module)

@spec lookup_by_module(module()) ::
  {:ok, LlmCore.Provider.Definition.t()} | {:error, :not_found}

Finds a provider definition by the implementing module.

suggest_alias(term, opts \\ [])

@spec suggest_alias(
  String.t(),
  keyword()
) :: [String.t()]

Suggests provider aliases that closely match the given term.

suggest_capable(requirements, opts \\ [])

@spec suggest_capable(
  map(),
  keyword()
) :: [map()]

Suggests providers capable of meeting the given capability requirements. Returns metadata so callers can surface cost tiers/model availability.