BerriAI/litellm · error · Exception

Missing webhook_url from environment

Error message

Missing webhook_url from environment

What it means

SlackAlerting.send_webhook posts a structured (currently budget) alert to a raw webhook URL taken exclusively from the WEBHOOK_URL environment variable (litellm/integrations/SlackAlerting/slack_alerting.py:1058-1061). Unlike the Slack paths, this method does not consult alert_to_webhook_url or default_webhook_url, so an unset WEBHOOK_URL aborts with an Exception.

Solutions

  1. Set WEBHOOK_URL in the environment of the litellm proxy process and restart it.
  2. If you meant Slack alerts generally, configure general_settings.alerting with webhook URLs and SLACK_WEBHOOK_URL instead of relying on send_webhook.
  3. In docker-compose/k8s, add WEBHOOK_URL to env/envFrom and verify with a printenv exec inside the container.
  4. Wrap send_webhook calls in try/except and log clearly when alert delivery is not configured.

Example fix

# before
# docker-compose.yml has no WEBHOOK_URL
await alerting.send_webhook(webhook_event)  # Exception: Missing webhook_url from environment

# after
# docker-compose.yml
 environment:
   - WEBHOOK_URL=https://hooks.example.com/xxx
await alerting.send_webhook(webhook_event)
Defensive patterns

Strategy: validation

Validate before calling

import os

webhook_url = os.getenv("WEBHOOK_URL")
if webhook_url is None:
    raise RuntimeError("WEBHOOK_URL not set; required for send_webhook budget alerts")
# safe to call: await alerting.send_webhook(webhook_event)

Try / catch

try:
    sent = await alerting.send_webhook(webhook_event)
except Exception as e:
    if "Missing webhook_url from environment" in str(e):
        # degrade gracefully: log locally, alert via another channel, do not crash the request path
        logger.warning("budget alert not delivered: WEBHOOK_URL unset")
    else:
        raise

Prevention

When it happens

Trigger: Enabling alerting with budget alerts ('budget_alerts' in the alerts list) and calling send_webhook without WEBHOOK_URL in the proxy process env; docker compose / k8s deployments missing the WEBHOOK_URL env entry; shell-exported variable not visible to the service user.

Common situations: Proxy operators configuring Slack via SLACK_WEBHOOK_URL but the budget-alert path needing the differently-named WEBHOOK_URL; secrets managed in config files while this code path reads only os.environ; CI smoke tests of alerting without env setup.

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


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

Appendix: source

Thrown at litellm/integrations/SlackAlerting/slack_alerting.py:1061

    async def model_removed_alert(self, model_name: str):
        pass

    async def send_webhook_alert(self, webhook_event: WebhookEvent) -> bool:
        """
        Sends structured alert to webhook, if set.

        Currently only implemented for budget alerts

        Returns -> True if sent, False if not.

        Raises Exception
            - if WEBHOOK_URL is not set
        """

        webhook_url: Final = os.getenv("WEBHOOK_URL", None)
        if webhook_url is None:
            raise Exception("Missing webhook_url from environment")

        payload: Final = webhook_event.model_dump_json()
        headers: Final = {"Content-type": "application/json"}

        response: Final = await self.async_http_handler.post(
            url=webhook_url,
            headers=headers,
            data=payload,
        )
        if response.status_code == 200:
            return True
        else:
            print("Error sending webhook alert. Error=", response.text)  # noqa: T201

        return False

    async def _check_if_using_premium_email_feature(
        self,

View on GitHub (pinned to 77b7c6c40c)