A fast, secure configuration management library for Elixir applications that provides easy access to API keys and environment variables. Part of the Jido ecosystem for LLM-powered applications.
Add jido_keys to your list of dependencies in mix.exs:
def deps do
[
{:jido_keys, "~> 0.1.0"}
]
endJidoKeys starts automatically - no setup required.
# Get values with optional defaults
JidoKeys.get(:openai_api_key)
JidoKeys.get(:openai_api_key, "fallback-key")
# Bang variant raises on missing keys
JidoKeys.get!(:openai_api_key)
# Check if keys exist
JidoKeys.has?(:openai_api_key)
JidoKeys.has_value?(:openai_api_key) # non-empty values only
# List all available keys
JidoKeys.list()Hierarchical resolution from multiple sources (in order of precedence):
- Runtime overrides (via
JidoKeys.put/2) - Environment variables (from
.envfiles and system) - Application config (from
config.exs) - Defaults (provided in
get/2)
# .env file
OPENAI_API_KEY=sk-1234567890
DATABASE_URL=postgres://localhost:5432/mydb
# Application config
config :jido_keys, :keys, %{
custom_key: "app_value"
}
# Runtime override
JidoKeys.put(:openai_api_key, "sk-override")Supports both atoms and strings with automatic normalization:
# All these access the same value
JidoKeys.get("OPENAI_API_KEY") # Standard env var format
JidoKeys.get("openai_api_key") # Lowercase
JidoKeys.get("OpenAI-API-Key") # Mixed case with special chars
JidoKeys.get(:openai_api_key) # Atom format
# Any string format works
JidoKeys.get("VERY_LONG_KEY_NAME_WITH_UNDERSCORES")
JidoKeys.get("key-with-dashes")
JidoKeys.get("key.with.dots")
JidoKeys.get("KEY@WITH#SPECIAL$CHARS")Special support for Livebook with LB_ prefixed environment variables:
# Environment variable: LB_OPENAI_API_KEY=sk-123
JidoKeys.get("openai_api_key") # Works with or without LB_ prefixBuilt-in logger filter that redacts sensitive information:
# Automatically redacts secrets in logs
Logger.info("API key: #{JidoKeys.get(:openai_api_key)}")
# Output: "API key: [REDACTED]"Memory-safe atom conversion for common LLM providers:
# Safe conversion to atoms (hardcoded allowlist)
JidoKeys.to_llm_atom("openai_api_key") # => :openai_api_key
JidoKeys.to_llm_atom("anthropic_api_key") # => :anthropic_api_key
# Unknown keys remain as strings
JidoKeys.to_llm_atom("custom_key") # => "custom_key"# Set values at runtime
JidoKeys.put(:test_key, "test_value")
# Reload configuration
JidoKeys.reload()
JidoKeys.reload(force: true)Perfect for testing with runtime configuration:
# In tests
JidoKeys.put(:test_api_key, "test-value")
assert JidoKeys.get(:test_api_key) == "test-value"
# Clean up after tests
JidoKeys.reload()Comprehensive error system with specific error types:
# Raises ArgumentError for missing keys
JidoKeys.get!(:missing_key)
# ** (ArgumentError) Configuration key :missing_key not found
# Custom error types for different scenarios
JidoKeys.Error.InvalidError
JidoKeys.Error.NotFoundError
JidoKeys.Error.ConfigurationError
JidoKeys.Error.ServerError- ETS-based storage for O(1) lookup times
- Concurrent reads with protected access
- Fast startup with efficient environment loading
Loads from multiple .env files with environment-specific overrides:
.env # Base environment
envs/.env # Environment-specific
envs/.dev.env # Development overrides
envs/.dev.overrides.env # Development overrides
get/2- Get value with optional defaultget!/1- Get value or raise exceptionhas?/1- Check if key existshas_value?/1- Check if key exists with non-empty valuelist/0- List all configuration keysput/2- Set value at runtimereload/0- Reload from all sourcesto_llm_atom/1- Safe atom conversion for LLM keys
Minimal external dependencies - only uses:
Dotenvyfor environment file loadingSplodefor error handling
- Supervised GenServer for reliability
- Comprehensive error handling
- Type specifications for all public functions
- Extensive test coverage (57 tests)
- Code quality checks (Credo, Dialyzer, formatting)
# Install dependencies
mix deps.get
# Run tests
mix test
# Run quality checks
mix quality
# Check formatting
mix format --check-formatted
# Run static analysis
mix dialyzer
mix credo --strictThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.