{"record":{"id":"ecd841f4b9463ca5","repo":"BerriAI/litellm","slug":"missing-api-key-a-call-is-being-made-to-llm-prov","errorCode":null,"errorMessage":"Missing API Key - A call is being made to LLM Provider but no key is set either in the environment variables ({LLM_PROVIDER}_API_KEY) or via params","messagePattern":"Missing API Key - A call is being made to LLM Provider but no key is set either in the environment variables \\((.+?)_API_KEY\\) or via params","errorType":"exception","errorClass":"DatabricksException","httpStatus":400,"severity":"error","filePath":"litellm/llms/databricks/common_utils.py","lineNumber":351,"sourceCode":"\n        # Check for OAuth M2M credentials (recommended for production)\n        client_id: Final = os.getenv(\"DATABRICKS_CLIENT_ID\")\n        client_secret: Final = os.getenv(\"DATABRICKS_CLIENT_SECRET\")\n\n        # Determine api_base first\n        if api_base is None:\n            api_base = os.getenv(\"DATABRICKS_API_BASE\")\n\n        if client_id and client_secret and api_base:\n            # Use OAuth M2M flow (preferred for production)\n            verbose_logger.debug(\"Using OAuth M2M authentication for Databricks\")\n            access_token: Final = self._get_oauth_m2m_token(api_base, client_id, client_secret)\n            headers = headers or {}\n            headers[\"Authorization\"] = f\"Bearer {access_token}\"\n            headers[\"Content-Type\"] = \"application/json\"\n        elif api_key is None and not headers:\n            if custom_endpoint is True:\n                raise DatabricksException(\n                    status_code=400,\n                    message=\"Missing API Key - A call is being made to LLM Provider but no key is set either in the environment variables ({LLM_PROVIDER}_API_KEY) or via params\",\n                )\n            else:\n                # Fallback to Databricks SDK (registers partner telemetry)\n                verbose_logger.debug(\"Using Databricks SDK for authentication\")\n                api_base, headers = self._get_databricks_credentials(\n                    api_base=api_base, api_key=api_key, headers=headers\n                )\n\n        if api_base is None:\n            if custom_endpoint:\n                raise DatabricksException(\n                    status_code=400,\n                    message=\"Missing API Base - A call is being made to LLM Provider but no api base is set either in the environment variables ({LLM_PROVIDER}_API_KEY) or via params\",\n                )\n            else:\n                api_base, headers = self._get_databricks_credentials(","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/databricks/common_utils.py#L333-L369","documentation":"databricks_validate_environment saw an api_base (or custom_endpoint=True) but no api_key, no auth headers, and no client_id/secret pair. For custom endpoints LiteLLM deliberately does not fall back to the SDK, so it raises 400 'Missing API Key'. The '{LLM_PROVIDER}' placeholder in the shipped text stands in for DATABRICKS.","triggerScenarios":"A custom LLM deployment/route pointing at a Databricks URL where api_base was supplied (or custom_endpoint flagged) but api_key was not passed and DATABRICKS_API_KEY is unset; proxy config with litellm_params: api_base only; per-call api_key dropped in a refactor.","commonSituations":"litellm_config.yaml deployment missing the api_key field; key stored under a differently-named env var; custom gateway setups where the key was expected to come from headers that were never set.","solutions":["Pass the key: add api_key='dapi...' to the call or the deployment's litellm_params","Or export DATABRICKS_API_KEY in the proxy/server process environment","If M2M was intended, set DATABRICKS_CLIENT_ID + DATABRICKS_CLIENT_SECRET + DATABRICKS_API_BASE instead","If header-based auth was intended, supply an Authorization header so the headers dict is non-empty"],"exampleFix":"# before — api_base only\nlitellm.completion(model='databricks/my-endpoint', messages=msgs,\n                  api_base='https://host/serving-endpoints')  # 400 Missing API Key\n\n# after\nlitellm.completion(\n    model='databricks/my-endpoint', messages=msgs,\n    api_base='https://host/serving-endpoints',\n    api_key=os.environ['DATABRICKS_API_KEY'],\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef custom_endpoint_auth_ok(api_base: str | None, api_key: str | None) -> bool:\n    if api_base is None:\n        return True  # SDK fallback path applies\n    return bool(api_key or os.getenv('DATABRICKS_API_KEY'))\n\nif not custom_endpoint_auth_ok(cfg.get('api_base'), cfg.get('api_key')):\n    raise RuntimeError('custom databricks endpoint requires api_key or DATABRICKS_API_KEY')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat api_base and api_key as a pair in configs - lint proxy/deployment YAML for one-without-the-other","Fail fast on boot when a custom endpoint lacks credentials"],"tags":["databricks","api-key","authentication","custom-endpoint"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}