BerriAI/litellm · error · Exception

DD_API_KEY is not set, set 'DD_API_KEY=<>

Error message

DD_API_KEY is not set, set 'DD_API_KEY=<>

What it means

DatadogLogger.__init__ resolves its API key from the dd_api_key argument or, only when allow_env_credentials is true, the DD_API_KEY environment variable. If neither yields a value it raises this generic Exception at construction time, before any logging can happen. Note passing allow_env_credentials=False without an explicit key guarantees this error.

Solutions

  1. export DD_API_KEY=<your Datadog API key> in the environment that runs litellm and restart
  2. Or pass the key explicitly: DatadogLogger(dd_api_key='...', dd_site='us5.datadoghq.com')
  3. Ensure the env actually reaches the process: docker --env-file, k8s Secret/env, systemd EnvironmentFile
  4. Keep allow_env_credentials at its default when you intend to use the env var

Example fix

# before
litellm_settings:
  callbacks: [datadog]  # DD_API_KEY unset -> Exception: DD_API_KEY is not set

# after (shell / deployment env)
export DD_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export DD_SITE=us5.datadoghq.com
litellm --config config.yaml
Defensive patterns

Strategy: validation

Validate before calling

import os

if not (os.getenv('DD_API_KEY') or explicit_dd_api_key):
    raise RuntimeError('DD_API_KEY missing: set it in the environment before adding the datadog callback')

Type guard

def datadog_configured() -> bool:
    import os
    return bool(os.getenv('DD_API_KEY'))

Try / catch

except Exception as e:
    if 'DD_API_KEY is not set' in str(e):
        set DD_API_KEY in the deployment env and restart; do not retry in-process
    raise

Prevention

When it happens

Trigger: Adding datadog to litellm callbacks without exporting DD_API_KEY; constructing DatadogLogger(allow_env_credentials=False) with no dd_api_key argument; deployment where the .env file is not loaded before the logger instantiates.

Common situations: Docker/k8s env vars missing from the deployment spec; CI environments without the Datadog secret; local .env present but not sourced in the shell running the proxy.

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/b7ce294badff5b7d. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/datadog/datadog.py:236

        dd_site: str | None = None,
        allow_env_credentials: bool = True,
    ) -> None:
        """
        Configure direct DataDog API connection

        Args:
            dd_api_key: Datadog API key. Falls back to DD_API_KEY env var when allow_env_credentials is True.
            dd_site: Datadog site. Falls back to DD_SITE env var.
            allow_env_credentials: When False, never read the API key from DD_API_KEY env var.

        Raises:
            Exception: If required credentials are not provided via args or env vars
        """
        resolved_api_key: Final = dd_api_key or (os.getenv("DD_API_KEY") if allow_env_credentials else None)
        resolved_site: Final = dd_site or os.getenv("DD_SITE")

        if resolved_api_key is None:
            raise Exception("DD_API_KEY is not set, set 'DD_API_KEY=<>")
        if resolved_site is None:
            raise Exception("DD_SITE is not set in .env, set 'DD_SITE=<>")

        self.DD_API_KEY = resolved_api_key
        self.intake_url = f"https://http-intake.logs.{resolved_site}/api/v2/logs"

    async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
        """
        Async Log success events to Datadog

        - Creates a Datadog payload
        - Adds the Payload to the in memory logs queue
        - Payload is flushed every 10 seconds or when batch size is greater than 100


        Raises:
            Raises a NON Blocking verbose_logger.exception if an error occurs
        """

View on GitHub (pinned to 77b7c6c40c)