JidoKeys (Jido Keys v1.0.0)

View Source

Easy access to LLM API keys and environment configuration.

Provides fast lookups with hierarchical resolution from session values, environment variables (via Dotenvy), application config, and defaults.

Basic Usage

# Returns value or `nil`
JidoKeys.get(:openai_api_key)

# Provide a default
JidoKeys.get(:openai_api_key, "demo-key")

# Bang variant raises ArgumentError
JidoKeys.get!(:openai_api_key)

# Boolean predicate
JidoKeys.has?(:openai_api_key)

# Inspect available keys (strings, already normalised)
JidoKeys.list()

Summary

Functions

Returns the value or default when the key is missing.

Returns the value or raises ArgumentError when the key is missing.

Returns true when the key exists and the value is non-empty.

Returns true when the key is present and its value is not nil or an empty string.

Returns the list of all loaded environment keys (as strings).

Sets a configuration value in the session store.

Reloads configuration from environment variables and files.

Safely converts a normalized string key to an atom if it's a known LLM key.

Types

key()

@type key() :: atom() | String.t()

value()

@type value() :: String.t() | nil

Functions

get(key, default \\ nil)

@spec get(key(), value()) :: value()

Returns the value or default when the key is missing.

Examples

iex> JidoKeys.get(:my_api_key)
"secret_value"

iex> JidoKeys.get(:missing_key, "fallback")
"fallback"

get!(key)

@spec get!(key()) :: String.t() | no_return()

Returns the value or raises ArgumentError when the key is missing.

Examples

iex> JidoKeys.get!(:my_api_key)
"secret_value"

iex> JidoKeys.get!(:missing)
** (ArgumentError) Configuration key :missing not found

has?(key)

@spec has?(key()) :: boolean()

Returns true when the key exists and the value is non-empty.

Examples

iex> JidoKeys.has?(:my_api_key)
true

iex> JidoKeys.has?(:missing_key)
false

has_value?(key)

@spec has_value?(key()) :: boolean()

Returns true when the key is present and its value is not nil or an empty string.

Examples

iex> JidoKeys.has_value?(:my_api_key)
true

iex> JidoKeys.has_value?(:empty_key)
false

list()

@spec list() :: [String.t()]

Returns the list of all loaded environment keys (as strings).

Examples

iex> JidoKeys.list()
["openai_api_key", "database_url", "secret_key_base"]

put(key, value)

@spec put(key(), String.t()) :: :ok

Sets a configuration value in the session store.

Examples

iex> JidoKeys.put(:my_test_key, "test_value")
:ok

iex> JidoKeys.put("another_key", "another_value")
:ok

reload(opts \\ [])

@spec reload(keyword()) :: :ok

Reloads configuration from environment variables and files.

Optional opts can be provided for future extensions.

Examples

iex> JidoKeys.reload()
:ok

iex> JidoKeys.reload(force: true)
:ok

to_llm_atom(key)

@spec to_llm_atom(String.t()) :: atom() | String.t()

Safely converts a normalized string key to an atom if it's a known LLM key.

This prevents memory leaks by only allowing predefined LLM keys to be converted to atoms. Unknown keys are returned as strings.

Examples

iex> JidoKeys.to_llm_atom("openai_api_key")
:openai_api_key

iex> JidoKeys.to_llm_atom("anthropic_api_key")
:anthropic_api_key

iex> JidoKeys.to_llm_atom("unknown_key")
"unknown_key"