Skip to main content

Config Utilities

Utilities for validating required environment variables, particularly API keys.

Overview

The verifiers.utils.config_utils module provides:
  • Environment variable validation
  • Clear error messages for missing keys
  • Guidance on setting secrets in different contexts

Functions

ensure_keys

Validate that required environment variables are set.
list[str]
required
List of environment variable names to check (e.g., ["OPENAI_API_KEY", "ANTHROPIC_API_KEY"]).
Raises: MissingKeyError if any keys are not set in the environment. Example:

Exceptions

MissingKeyError

Exception raised when required environment variables are missing. Provides helpful error messages with context-specific guidance for setting environment variables in different deployment scenarios. Attributes:
list[str]
List of missing environment variable names.
Error Message Format:
Example:

Example Usage

Basic Validation

Multiple Keys

Custom Services

Error Handling

Setting Environment Variables

Local Development

Environments Hub CI

  1. Go to your environment’s page on Environments Hub
  2. Click Settings
  3. Add secrets in the Environment Variables section
  4. Secrets are automatically injected during CI runs

Hosted Training

Create a secrets.env file:
Reference in your training config:

Best Practices

1. Validate Early

Call ensure_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_KEY for API keys
  • *_URL for endpoints
  • *_TOKEN for 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