{"record":{"id":"5d76712833c9b395","repo":"BerriAI/litellm","slug":"dd-api-key-is-not-set-set-dd-api-key-5d7671","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_llm_obs.py","lineNumber":71,"sourceCode":"\n            if self.is_mock_mode:\n                create_mock_datadog_client()\n                verbose_logger.debug(\"[DATADOG MOCK] DataDogLLMObs logger initialized in mock mode\")\n\n            # Configure DataDog endpoint (Agent or Direct API)\n            # Use LITELLM_DD_AGENT_HOST to avoid conflicts with ddtrace's DD_AGENT_HOST\n            # Check for agent mode FIRST - agent mode doesn't require DD_API_KEY or DD_SITE\n            dd_agent_host: Final = os.getenv(\"LITELLM_DD_AGENT_HOST\")\n\n            self.async_client = get_async_httpx_client(llm_provider=httpxSpecialProvider.LoggingCallback)\n            self.DD_API_KEY = os.getenv(\"DD_API_KEY\")\n\n            if dd_agent_host:\n                self._configure_dd_agent(dd_agent_host=dd_agent_host)\n            else:\n                # Only require DD_API_KEY and DD_SITE for direct API mode\n                if os.getenv(\"DD_API_KEY\", None) is None:\n                    raise Exception(\"DD_API_KEY is not set, set 'DD_API_KEY=<>'\")\n                if os.getenv(\"DD_SITE\", None) is None:\n                    raise Exception(\"DD_SITE is not set, set 'DD_SITE=<>', example sit = `us5.datadoghq.com`\")\n                self._configure_dd_direct_api()\n\n            # Optional override for testing\n            dd_base_url: Final = get_datadog_base_url_from_env()\n            if dd_base_url:\n                self.intake_url = f\"{dd_base_url}/api/intake/llm-obs/v1/trace/spans\"\n\n            asyncio.create_task(self.periodic_flush())\n            self.flush_lock = asyncio.Lock()\n            self.log_queue: list[LLMObsPayload] = []\n\n            #########################################################\n            # Handle datadog_llm_observability_params set as litellm.datadog_llm_observability_params\n            #########################################################\n            dict_datadog_llm_obs_params: Final = self._get_datadog_llm_obs_params()\n            kwargs.update(dict_datadog_llm_obs_params)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/datadog/datadog_llm_obs.py#L53-L89","documentation":"DataDogLLMObsLogger.__init__ decides between two modes: agent mode (LITELLM_DD_AGENT_HOST set, no API key needed) and direct-API mode. In direct mode both DD_API_KEY and DD_SITE must be present in the environment; a missing DD_API_KEY raises this Exception during construction. Because custom loggers are instantiated when callbacks load (e.g. at proxy startup), this error typically aborts startup.","triggerScenarios":"Configuring callbacks: [\"datadog_llm_obs\"] in litellm_settings without DD_API_KEY exported; intending agent mode but typo-ing LITELLM_DD_AGENT_HOST so the code falls through to the direct-API branch; running in CI/docker where the secret was never injected.","commonSituations":"Env var set in an interactive shell but not in the systemd unit / docker-compose / k8s deployment; key stored under a different name (DATADOG_API_KEY, DD_API_KEY_2); .env file not loaded by the service.","solutions":["Export DD_API_KEY in the environment of the process running litellm (docker-compose env:, systemd Environment=, k8s secret) and confirm with printenv | grep DD_","If you meant to ship via the Datadog agent, set LITELLM_DD_AGENT_HOST instead — agent mode skips the key requirement entirely","Double-check the exact variable name is DD_API_KEY, not DATADOG_API_KEY"],"exampleFix":"# before (container starts without secrets)\ndocker run my-proxy  # Exception: DD_API_KEY is not set\n\n# after\ndocker run -e DD_API_KEY=$DD_API_KEY -e DD_SITE=us5.datadoghq.com my-proxy","handlingStrategy":"validation","validationCode":"import os\n\ndef can_enable_datadog_llm_obs() -> bool:\n    \"\"\"Direct mode needs DD_API_KEY+DD_SITE; agent mode needs LITELLM_DD_AGENT_HOST.\"\"\"\n    if os.getenv(\"LITELLM_DD_AGENT_HOST\"):\n        return True\n    return bool(os.getenv(\"DD_API_KEY\")) and bool(os.getenv(\"DD_SITE\"))\n\n# in config:\n# callbacks = [DataDogLLMObsLogger()] if can_enable_datadog_llm_obs() else []","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast at boot: assert the mode variables before registering the callback","In k8s/docker, use a readiness check that runs printenv for DD_API_KEY and DD_SITE","Prefer agent mode (LITELLM_DD_AGENT_HOST) when you don't want API keys near the proxy"],"tags":["datadog","llm-obs","env-var","initialization","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}