{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/datadog/datadog.py#L218-L254","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["export DD_API_KEY=<your Datadog API key> in the environment that runs litellm and restart","Or pass the key explicitly: DatadogLogger(dd_api_key='...', dd_site='us5.datadoghq.com')","Ensure the env actually reaches the process: docker --env-file, k8s Secret/env, systemd EnvironmentFile","Keep allow_env_credentials at its default when you intend to use the env var"],"exampleFix":"# before\nlitellm_settings:\n  callbacks: [datadog]  # DD_API_KEY unset -> Exception: DD_API_KEY is not set\n\n# after (shell / deployment env)\nexport DD_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nexport DD_SITE=us5.datadoghq.com\nlitellm --config config.yaml","handlingStrategy":"validation","validationCode":"import os\n\nif not (os.getenv('DD_API_KEY') or explicit_dd_api_key):\n    raise RuntimeError('DD_API_KEY missing: set it in the environment before adding the datadog callback')","typeGuard":"def datadog_configured() -> bool:\n    import os\n    return bool(os.getenv('DD_API_KEY'))","tryCatchPattern":"except Exception as e:\n    if 'DD_API_KEY is not set' in str(e):\n        set DD_API_KEY in the deployment env and restart; do not retry in-process\n    raise","preventionTips":["Add DD_API_KEY and DD_SITE to deployment env specs (docker env-file, k8s Secret)","Only set allow_env_credentials=False when you pass dd_api_key explicitly","Validate required env vars in a startup preflight check"],"tags":["datadog","environment-variables","credentials","logging","litellm"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}