BerriAI/litellm · error · AimGuardrailMissingSecrets

Couldn't get Aim api key, either set the `AIM_API_KEY` in th

Error message

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

What it means

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.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/aim/aim.py:70

            GuardrailEventHooks.pre_call,
            GuardrailEventHooks.during_call,
            GuardrailEventHooks.post_call,
        ]

    def __init__(self, api_key: str | None = None, api_base: str | None = None, **kwargs):
        kwargs.setdefault("supported_event_hooks", list(self.get_supported_event_hooks()))
        ssl_verify: Final = kwargs.pop("ssl_verify", None)
        self.async_handler = get_async_httpx_client(
            llm_provider=httpxSpecialProvider.GuardrailCallback,
            params={"ssl_verify": ssl_verify} if ssl_verify is not None else None,
        )
        self.api_key = api_key or os.environ.get("AIM_API_KEY")
        if not self.api_key:
            msg: Final = (
                "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"
            )
            raise AimGuardrailMissingSecrets(msg)
        self.api_base = api_base or os.environ.get("AIM_API_BASE") or "https://api.aim.security"
        self.ws_api_base = self.api_base.replace("http://", "ws://").replace("https://", "wss://")
        self.dlp_entities: list[dict] = []
        self._max_dlp_entities = 100
        super().__init__(**kwargs)

    async def async_pre_call_hook(
        self,
        user_api_key_dict: UserAPIKeyAuth,
        cache: DualCache,
        data: dict,
        call_type: CallTypesLiteral,
    ) -> Exception | str | dict | None:
        verbose_proxy_logger.debug("Inside AIM Pre-Call Hook")
        return await self.call_aim_guardrail(data, hook="pre_call", key_alias=user_api_key_dict.key_alias)

    async def async_moderation_hook(
        self,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set the AIM_API_KEY environment variable, or pass api_key in the guardrail config.

Example fix

export AIM_API_KEY=<your-aim-key>
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/guardrails/guardrail_hooks/aim/aim.py:70 when the library encounters an invalid state.

Common situations: The Aim guardrail has no API key from env or config.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/4983f3d2641bbe89. Report an issue: GitHub.