BerriAI/litellm · critical · ValueError
EnkryptAI API key is required. Set ENKRYPTAI_API_KEY environ
Error message
EnkryptAI API key is required. Set ENKRYPTAI_API_KEY environment variable or pass api_key parameter.
What it means
ValueError raised in EnkryptAIGuardrail.__init__ when both the api_key parameter and the ENKRYPTAI_API_KEY environment variable are empty. The guardrail is constructed when the proxy loads its guardrails-config, so the error aborts guardrail initialization (typically proxy startup) before any moderation call is made.
Source
Thrown at litellm/proxy/guardrails/guardrail_hooks/enkryptai/enkryptai.py:59
GUARDRAIL_NAME: Final = "enkryptai"
class EnkryptAIGuardrails(CustomGuardrail):
def __init__(
self,
guardrail_name: str = "litellm_test",
api_key: str | None = None,
api_base: str | None = None,
policy_name: str | None = None,
**kwargs,
):
self.async_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.GuardrailCallback)
# Set API configuration
self.api_key = api_key or os.getenv("ENKRYPTAI_API_KEY")
if not self.api_key:
raise ValueError(
"EnkryptAI API key is required. Set ENKRYPTAI_API_KEY environment variable or pass api_key parameter."
)
self.api_base = api_base or os.getenv("ENKRYPTAI_API_BASE", "https://api.enkryptai.com")
self.api_url = f"{self.api_base}/guardrails/policy/detect"
# Policy name can be passed as parameter or use guardrail_name
self.policy_name = policy_name
self.guardrail_name = guardrail_name
self.guardrail_provider = "enkryptai"
# store kwargs as optional_params
self.optional_params = kwargs
# Set supported event hooks
kwargs.setdefault("supported_event_hooks", list(self.get_supported_event_hooks()))
super().__init__(guardrail_name=guardrail_name, **kwargs)View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set ENKRYPTAI_API_KEY in the environment the proxy process actually runs in.
- Or pass api_key: os.environ/ENKRYPTAI_API_KEY in the guardrail's litellm_params.
- Restart the proxy — the check runs once at construction.
- Confirm the variable name spelling with printenv | grep ENKRYPT in the same shell/service context.
Example fix
# before litellm_params: guardrail: enkryptai policy_name: my-policy # after litellm_params: guardrail: enkryptai policy_name: my-policy api_key: os.environ/ENKRYPTAI_API_KEY
Defensive patterns
Strategy: validation
Validate before calling
import os
if not (os.getenv('ENKRYPTAI_API_KEY') or cfg.litellm_params.get('api_key')):
raise SystemExit('ENKRYPTAI_API_KEY not set — refusing to start with enkryptai guardrail') Try / catch
try:
guardrail = EnkryptAIGuardrail(litellm_params=cfg)
except ValueError as e:
if 'ENKRYPTAI_API_KEY' in str(e):
logger.error('deploy misconfigured: %s', e)
raise
raise Prevention
- Inject ENKRYPTAI_API_KEY via your secret manager into every environment loading the guardrail.
- Add a startup env-var assertion to your deploy pipeline.
- Use os.environ/ENKRYPTAI_API_KEY references in config, never literal keys.
When it happens
Trigger: An enkryptai guardrail entry with no api_key in litellm_params while ENKRYPTAI_API_KEY is unset in the proxy's environment; deployments where the secret exists locally but was not injected into the container/service.
Common situations: Missing entry in docker-compose environment or Kubernetes secret; env var named differently (ENKRYPT_AI_API_KEY); .env file not loaded by the service runner; CI runs without secrets.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- DynamoAI API key is required. Set DYNAMOAI_API_KEY environme
- api_base is required for Generic Guardrail API. Set GENERIC_
- Gray Swan guardrail requires a guardrail_name
- Gray Swan API key missing. Set `GRAYSWAN_API_KEY` or pass `a
- llm_as_a_judge guardrail requires a guardrail_name
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/fc34943835babf16.
Report an issue: GitHub.