In-memory credential resolver for LLM providers.
Credentials are resolved on demand from explicit options, environment variables, H provider settings, or the Google Cloud CLI for ADC, and optionally cached in memory with a TTL safety margin. Secrets are never persisted to disk or included in inspected/sanitized error values.
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all cached tokens from a running cache process.
Returns true if provider has credentials available in opts or the
environment without executing external token helpers.
Returns the list of providers that currently have credentials configured in
opts or the environment, ordered by @provider_priority.
Resolves in-memory credentials for provider.
Redacts secret values (access_token, api_key, Bearer ..., etc.) from maps,
lists, tuples, exceptions, and strings so credentials never leak into logs or errors.
Starts an in-memory credential cache process.
Types
@type anonymous_credentials() :: %{auth_mode: :none}
@type api_key_credentials() :: %{api_key: String.t()}
@type credentials() :: vertex_credentials() | api_key_credentials() | anonymous_credentials() | codex_credentials()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_cache(GenServer.server()) :: :ok
Clears all cached tokens from a running cache process.
Returns true if provider has credentials available in opts or the
environment without executing external token helpers.
Returns the list of providers that currently have credentials configured in
opts or the environment, ordered by @provider_priority.
@spec resolve(atom() | String.t(), keyword()) :: {:ok, credentials()} | {:error, term()}
Resolves in-memory credentials for provider.
Supported providers:
:google_vertex/"google_vertex"/"google-vertex":openai_codex/"openai-codex"(OAuth access token):anthropic/"anthropic"(ANTHROPIC_API_KEY):openai/"openai"(OPENAI_API_KEY):openrouter/"openrouter"(OPENROUTER_API_KEY):deepseek/"deepseek"(DEEPSEEK_API_KEY):google/"google"(GOOGLE_API_KEY):ollama/"ollama"(no key required; returns%{auth_mode: :none})
Options:
:access_token- Explicit bearer token for Vertex or Codex:settings- H-owned provider settings map (populated by the adapter):account_id- Explicit Codex account ID; otherwise derived from the token:project_id- OverrideGOOGLE_CLOUD_PROJECT:region- OverrideGOOGLE_CLOUD_REGION(defaults to"global"):api_key- Explicit API key override (Vertex uses Express Mode):credentials_path- Override the Vertex ADC file path:fetcher- Injectable 0-arity or 1-arity callback for:google_vertex:cache- Cache server pid/name, orfalseto bypass cache:env- Optional%{String.t() => String.t()}map overridingSystem.get_env/1:ttl_margin_ms/:default_ttl_ms/:now_fn- Timing overrides when uncached or configuring cache
Redacts secret values (access_token, api_key, Bearer ..., etc.) from maps,
lists, tuples, exceptions, and strings so credentials never leak into logs or errors.
@spec start_link(keyword()) :: GenServer.on_start()
Starts an in-memory credential cache process.
Options:
:name- Optional registered name (defaults tonil):ttl_margin_ms- Safety margin subtracted from token expiration (default60_000):default_ttl_ms- Fallback TTL when helper output omits expiration (default3_600_000):now_fn- Zero-arity clock function returning monotonic/unix ms (default&System.system_time(:millisecond))