Agentic.LLM.Credentials (agentic v0.2.2)

Copy Markdown

Resolved credentials for a single provider.

resolve/1 walks the provider's declared env_vars/0 in priority order and returns the first non-empty value wrapped in a %Credentials{} struct. The provider knows its own env var names; nothing else does.

resolve/2 accepts an opts keyword list. If opts[:api_key] is set, it is used directly instead of looking up env vars. This allows the host application to inject keys per-call (e.g. from an encrypted store).

Runtime credentials can also be stored via put/2 and are checked before environment variables.

Summary

Functions

Returns true when the provider has a usable credential.

Remove all credentials from the runtime ETS store.

Remove a single credential from the runtime ETS store.

Initialize the ETS credential store. Call once at app startup.

Store a credential in the runtime ETS store.

Resolve credentials for a provider module.

Types

t()

@type t() :: %Agentic.LLM.Credentials{
  api_key: String.t() | nil,
  base_url_override: String.t() | nil,
  headers: [{String.t(), String.t()}],
  source: {:env, String.t()} | :injected | :none
}

Functions

available?(provider)

@spec available?(module()) :: boolean()

Returns true when the provider has a usable credential.

clear()

@spec clear() :: :ok

Remove all credentials from the runtime ETS store.

delete(env_var)

@spec delete(String.t()) :: :ok

Remove a single credential from the runtime ETS store.

init_store()

@spec init_store() :: :ok

Initialize the ETS credential store. Call once at app startup.

put(env_var, key)

@spec put(String.t(), String.t()) :: true

Store a credential in the runtime ETS store.

resolve(provider, opts \\ [])

@spec resolve(
  module(),
  keyword()
) :: {:ok, t()} | :not_configured

Resolve credentials for a provider module.

When opts[:api_key] is provided, uses that directly instead of looking up environment variables. Falls back to the runtime ETS store, then to env var lookup.

iex> Credentials.resolve(Agentic.LLM.Provider.OpenAI)
{:ok, %Credentials{api_key: "sk-...", source: {:env, "OPENAI_API_KEY"}}}

iex> Credentials.resolve(Agentic.LLM.Provider.OpenAI, api_key: "sk-direct")
{:ok, %Credentials{api_key: "sk-direct", source: :injected}}