Config Utilities
Utilities for validating required environment variables, particularly API keys.Overview
Theverifiers.utils.config_utils module provides:
- Environment variable validation
- Clear error messages for missing keys
- Guidance on setting secrets in different contexts
Functions
ensure_keys
list[str]
required
List of environment variable names to check (e.g.,
["OPENAI_API_KEY", "ANTHROPIC_API_KEY"]).MissingKeyError if any keys are not set in the environment.
Example:
Exceptions
MissingKeyError
list[str]
List of missing environment variable names.
Example Usage
Basic Validation
Multiple Keys
Custom Services
Error Handling
Setting Environment Variables
Local Development
Environments Hub CI
- Go to your environment’s page on Environments Hub
- Click Settings
- Add secrets in the Environment Variables section
- Secrets are automatically injected during CI runs
Hosted Training
Create asecrets.env file:
Best Practices
1. Validate Early
Callensure_keys() in load_environment() to fail fast:
2. Document Required Keys
List required keys in your environment’s README:4. Use Consistent Key Names
Follow common conventions:*_API_KEYfor API keys*_URLfor endpoints*_TOKENfor auth tokens
Common API Key Names
OpenAI API key (starts with
sk-)Anthropic API key (starts with
sk-ant-)Prime API key for inference
Browserbase API key for browser environments
GitHub personal access token
HuggingFace access token
Error Message Customization
The default error message provides context-specific guidance. You can catch and customize:See Also
- Environment - Base environment class
- ClientConfig - Configuring API clients