{"record":{"id":"b7ce294badff5b7d","repo":"BerriAI/litellm","slug":"dd-api-key-is-not-set-set-dd-api-key","errorCode":null,"errorMessage":"DD_API_KEY is not set, set 'DD_API_KEY=<>","messagePattern":"DD_API_KEY is not set, set 'DD_API_KEY=<>","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/datadog/datadog.py","lineNumber":236,"sourceCode":"        dd_site: str | None = None,\n        allow_env_credentials: bool = True,\n    ) -> None:\n        \"\"\"\n        Configure direct DataDog API connection\n\n        Args:\n            dd_api_key: Datadog API key. Falls back to DD_API_KEY env var when allow_env_credentials is True.\n            dd_site: Datadog site. Falls back to DD_SITE env var.\n            allow_env_credentials: When False, never read the API key from DD_API_KEY env var.\n\n        Raises:\n            Exception: If required credentials are not provided via args or env vars\n        \"\"\"\n        resolved_api_key: Final = dd_api_key or (os.getenv(\"DD_API_KEY\") if allow_env_credentials else None)\n        resolved_site: Final = dd_site or os.getenv(\"DD_SITE\")\n\n        if resolved_api_key is None:\n            raise Exception(\"DD_API_KEY is not set, set 'DD_API_KEY=<>\")\n        if resolved_site is None:\n            raise Exception(\"DD_SITE is not set in .env, set 'DD_SITE=<>\")\n\n        self.DD_API_KEY = resolved_api_key\n        self.intake_url = f\"https://http-intake.logs.{resolved_site}/api/v2/logs\"\n\n    async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):\n        \"\"\"\n        Async Log success events to Datadog\n\n        - Creates a Datadog payload\n        - Adds the Payload to the in memory logs queue\n        - Payload is flushed every 10 seconds or when batch size is greater than 100\n\n\n        Raises:\n            Raises a NON Blocking verbose_logger.exception if an error occurs\n        \"\"\"","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/datadog/datadog.py#L218-L254","documentation":"DataDogLogger resolves its API key as dd_api_key if passed, otherwise DD_API_KEY from the environment — and only when allow_env_credentials is True. If both are absent the constructor raises a generic Exception immediately, so the logger cannot even be instantiated. It is a bootstrap/config error for the Datadog logging integration.","triggerScenarios":"Adding DataDogLogger to litellm_settings callbacks (or litellm.callbacks = [...]) in an environment where DD_API_KEY is unset and no dd_api_key argument was supplied; or allow_env_credentials=False with no explicit key, which always disables the env fallback.","commonSituations":"Env vars set in one shell but the proxy runs under systemd/docker without them; .env file not loaded by the deployment; allow_env_credentials flipped to False for secret-hygiene reasons without providing the key explicitly.","solutions":["Export DD_API_KEY in the process running litellm (docker-compose environment:, k8s secret env, .env for local dev)","Or pass dd_api_key explicitly when constructing DataDogLogger","If allow_env_credentials=False is intentional, supply the key via the dd_api_key argument every time"],"exampleFix":"# before\nlitellm.callbacks = [\"datadog\"]  # DD_API_KEY unset\n\n# after\n# docker-compose.yml\nservices:\n  litellm:\n    environment:\n      - DD_API_KEY=${DD_API_KEY}\n      - DD_SITE=us5.datadoghq.com","handlingStrategy":"validation","validationCode":"import os\n\ndef datadog_logger_ready() -> bool:\n    return bool(os.getenv(\"DD_API_KEY\"))\n\nif \"datadog\" in callbacks and not datadog_logger_ready():\n    raise SystemExit(\"Set DD_API_KEY before enabling the datadog callback\")","typeGuard":null,"tryCatchPattern":"try:\n    DataDogLogger()\nexcept Exception as e:\n    if \"DD_API_KEY\" in str(e):\n        fail_fast_on_missing_secret(\"DD_API_KEY\")\n    raise","preventionTips":["Fail fast at startup: check required env vars before constructing callbacks","Manage DD_API_KEY/DD_SITE as a unit in one secret store","In docker/k8s, use explicit env entries (not inherited shells) so vars reach the proxy process"],"tags":["datadog","logging","env-vars","config"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}