ReqLLM.Keys (ReqLLM v1.0.0-rc.3)
View SourceSimple API key lookup with configurable precedence.
Precedence (first match wins):
:api_keyoption (per request)Application.get_env/2System.get_env/1JidoKeys.get/1(includes ReqLLM.put_key)
Happy path: works with ReqLLM.Model structs and provider atoms.
Uses each provider's default_env_key/0 callback when available.
Examples
# Recommended: Use ReqLLM.put_key
ReqLLM.put_key(:anthropic_api_key, "sk-ant-...")
# Works with models (extracts provider automatically)
model = ReqLLM.Model.from("anthropic:claude-3-sonnet")
key = ReqLLM.Keys.get!(model)
# Per-request override (highest priority)
key = ReqLLM.Keys.get!(model, api_key: "sk-override-...")
# Debug key source
{:ok, key, source} = ReqLLM.Keys.get(model)
Logger.debug("Using key from #{source}")Configuration Options
# Recommended: ReqLLM.put_key (secure in-memory)
ReqLLM.put_key(:anthropic_api_key, "sk-ant-...")
# Alternative: Application config
Application.put_env(:req_llm, :anthropic_api_key, "sk-ant-...")
# Alternative: Environment variable
System.put_env("ANTHROPIC_API_KEY", "sk-ant-...")
# .env files are auto-loaded via JidoKeys
Summary
Functions
Returns the application config key for a provider.
Returns the expected environment variable name for a provider.
See ReqLLM.Keys.get/2.
See ReqLLM.Keys.get!/2.
Retrieves API key for a provider/model with source information.
Retrieves API key for a provider/model, raising on failure.
Types
Functions
Returns the application config key for a provider.
Examples
iex> ReqLLM.Keys.config_key(:anthropic)
:anthropic_api_key
Returns the expected environment variable name for a provider.
Uses the provider's default_env_key callback if available, otherwise uses the provider registry.
Examples
iex> ReqLLM.Keys.env_var_name(:anthropic)
"ANTHROPIC_API_KEY"
See ReqLLM.Keys.get/2.
See ReqLLM.Keys.get!/2.
@spec get( ReqLLM.Model.t() | atom(), keyword() ) :: {:ok, String.t(), key_source()} | {:error, String.t()}
Retrieves API key for a provider/model with source information.
@spec get!( ReqLLM.Model.t() | atom(), keyword() ) :: String.t() | no_return()
Retrieves API key for a provider/model, raising on failure.