synth_ai.core.env
Environment resolution utilities.
This module provides non-interactive environment variable resolution
for use by SDK and CLI. It consolidates the various env resolution
patterns into a clean API.
Functions
get_api_key
env_key: Environment variable name to checkrequired: If True, raises AuthenticationError when not found
- API key string or None if not required and not found
AuthenticationError: If required and not found
get_backend_url
- SYNTH_BACKEND_URL env var (if set)
- Mode-specific URL based on SYNTH_BACKEND_MODE or explicit mode
- Default to production
mode: Force a specific mode (prod/dev/local), or detect from env
- Backend URL (without trailing /api)
resolve_env_file
explicit_path: If provided, use this path directlysearch_cwd: If True, search current directory for .env
- Path to .env file, or None if not found
load_env_file
path: Path to .env file
- Dict mapping env var names to values
mask_value
value: The value to maskvisible_chars: Number of characters to show at start and end
- Masked string like “abc…xyz”
get_backend_from_env
- BACKEND_OVERRIDE = full URL (with or without /api)
- SYNTH_BACKEND_URL_OVERRIDE = local|dev|prod (case-insensitive)
- LOCAL_BACKEND_URL, TESTING_LOCAL_SYNTH_API_KEY
- DEV_BACKEND_URL, DEV_SYNTH_API_KEY
- PROD_BACKEND_URL, TESTING_PROD_SYNTH_API_KEY (fallback to SYNTH_API_KEY)
- Tuple of (base_url, api_key)