{"record":{"id":"fc34943835babf16","repo":"BerriAI/litellm","slug":"enkryptai-api-key-is-required-set-enkryptai-api-k","errorCode":null,"errorMessage":"EnkryptAI API key is required. Set ENKRYPTAI_API_KEY environment variable or pass api_key parameter.","messagePattern":"EnkryptAI API key is required\\. Set ENKRYPTAI_API_KEY environment variable or pass api_key parameter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"litellm/proxy/guardrails/guardrail_hooks/enkryptai/enkryptai.py","lineNumber":59,"sourceCode":"\nGUARDRAIL_NAME: Final = \"enkryptai\"\n\n\nclass EnkryptAIGuardrails(CustomGuardrail):\n    def __init__(\n        self,\n        guardrail_name: str = \"litellm_test\",\n        api_key: str | None = None,\n        api_base: str | None = None,\n        policy_name: str | None = None,\n        **kwargs,\n    ):\n        self.async_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.GuardrailCallback)\n\n        # Set API configuration\n        self.api_key = api_key or os.getenv(\"ENKRYPTAI_API_KEY\")\n        if not self.api_key:\n            raise ValueError(\n                \"EnkryptAI API key is required. Set ENKRYPTAI_API_KEY environment variable or pass api_key parameter.\"\n            )\n\n        self.api_base = api_base or os.getenv(\"ENKRYPTAI_API_BASE\", \"https://api.enkryptai.com\")\n        self.api_url = f\"{self.api_base}/guardrails/policy/detect\"\n\n        # Policy name can be passed as parameter or use guardrail_name\n        self.policy_name = policy_name\n        self.guardrail_name = guardrail_name\n        self.guardrail_provider = \"enkryptai\"\n\n        # store kwargs as optional_params\n        self.optional_params = kwargs\n\n        # Set supported event hooks\n        kwargs.setdefault(\"supported_event_hooks\", list(self.get_supported_event_hooks()))\n\n        super().__init__(guardrail_name=guardrail_name, **kwargs)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/enkryptai/enkryptai.py#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nlitellm_params:\n  guardrail: enkryptai\n  policy_name: my-policy\n\n# after\nlitellm_params:\n  guardrail: enkryptai\n  policy_name: my-policy\n  api_key: os.environ/ENKRYPTAI_API_KEY","handlingStrategy":"validation","validationCode":"import os\n\nif not (os.getenv('ENKRYPTAI_API_KEY') or cfg.litellm_params.get('api_key')):\n    raise SystemExit('ENKRYPTAI_API_KEY not set — refusing to start with enkryptai guardrail')","typeGuard":null,"tryCatchPattern":"try:\n    guardrail = EnkryptAIGuardrail(litellm_params=cfg)\nexcept ValueError as e:\n    if 'ENKRYPTAI_API_KEY' in str(e):\n        logger.error('deploy misconfigured: %s', e)\n        raise\n    raise","preventionTips":["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."],"tags":["enkryptai","guardrail","api-key","config","startup"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}