{"record":{"id":"4983f3d2641bbe89","repo":"BerriAI/litellm","slug":"couldn-t-get-aim-api-key-either-set-the-aim-api","errorCode":null,"errorMessage":"Couldn't get Aim api key, either set the `AIM_API_KEY` in the environment or pass it as a parameter to the guardrail in the config file","messagePattern":"Couldn't get Aim api key, either set the `AIM_API_KEY` in the environment or pass it as a parameter to the guardrail in the config file","errorType":"exception","errorClass":"AimGuardrailMissingSecrets","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/aim/aim.py","lineNumber":70,"sourceCode":"            GuardrailEventHooks.pre_call,\n            GuardrailEventHooks.during_call,\n            GuardrailEventHooks.post_call,\n        ]\n\n    def __init__(self, api_key: str | None = None, api_base: str | None = None, **kwargs):\n        kwargs.setdefault(\"supported_event_hooks\", list(self.get_supported_event_hooks()))\n        ssl_verify: Final = kwargs.pop(\"ssl_verify\", None)\n        self.async_handler = get_async_httpx_client(\n            llm_provider=httpxSpecialProvider.GuardrailCallback,\n            params={\"ssl_verify\": ssl_verify} if ssl_verify is not None else None,\n        )\n        self.api_key = api_key or os.environ.get(\"AIM_API_KEY\")\n        if not self.api_key:\n            msg: Final = (\n                \"Couldn't get Aim api key, either set the `AIM_API_KEY` in the environment or \"\n                \"pass it as a parameter to the guardrail in the config file\"\n            )\n            raise AimGuardrailMissingSecrets(msg)\n        self.api_base = api_base or os.environ.get(\"AIM_API_BASE\") or \"https://api.aim.security\"\n        self.ws_api_base = self.api_base.replace(\"http://\", \"ws://\").replace(\"https://\", \"wss://\")\n        self.dlp_entities: list[dict] = []\n        self._max_dlp_entities = 100\n        super().__init__(**kwargs)\n\n    async def async_pre_call_hook(\n        self,\n        user_api_key_dict: UserAPIKeyAuth,\n        cache: DualCache,\n        data: dict,\n        call_type: CallTypesLiteral,\n    ) -> Exception | str | dict | None:\n        verbose_proxy_logger.debug(\"Inside AIM Pre-Call Hook\")\n        return await self.call_aim_guardrail(data, hook=\"pre_call\", key_alias=user_api_key_dict.key_alias)\n\n    async def async_moderation_hook(\n        self,","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/aim/aim.py#L52-L88","documentation":"Raised while initializing the Aim guardrail callback when no API key can be found: neither an explicit api_key parameter in the guardrail's litellm_params nor an AIM_API_KEY environment variable. The callback needs the key to authenticate to Aim's API, so guardrail initialization fails at proxy startup/load time with setup instructions embedded.","triggerScenarios":"Thrown at litellm/proxy/guardrails/guardrail_hooks/aim/aim.py:70 when the library encounters an invalid state.","commonSituations":"The Aim guardrail has no API key from env or config.","solutions":["Set the AIM_API_KEY environment variable, or pass api_key in the guardrail config."],"exampleFix":"export AIM_API_KEY=<your-aim-key>","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}