{"record":{"id":"95ec2f997e3e553b","repo":"BerriAI/litellm","slug":"if-the-databricks-base-url-and-api-key-are-not-set","errorCode":null,"errorMessage":"If the Databricks base URL and API key are not set, the databricks-sdk Python library must be installed. Please install the databricks-sdk, set {LLM_PROVIDER}_API_BASE and {LLM_PROVIDER}_API_KEY environment variables, or provide the base URL and API key as arguments.","messagePattern":"If the Databricks base URL and API key are not set, the databricks-sdk Python library must be installed\\. Please install the databricks-sdk, set (.+?)_API_BASE and (.+?)_API_KEY environment variables, or provide the base URL and API key as arguments\\.","errorType":"exception","errorClass":"DatabricksException","httpStatus":400,"severity":"error","filePath":"litellm/llms/databricks/common_utils.py","lineNumber":294,"sourceCode":"        \"\"\"\n        headers = headers or {\"Content-Type\": \"application/json\"}\n        try:\n            from databricks.sdk import WorkspaceClient, useragent\n\n            # Register LiteLLM as partner for Databricks telemetry attribution\n            useragent.with_partner(\"litellm\")\n\n            databricks_client: Final = WorkspaceClient()\n\n            api_base = api_base or f\"{databricks_client.config.host}/serving-endpoints\"\n\n            if api_key is None:\n                databricks_auth_headers: Final[dict[str, str]] = databricks_client.config.authenticate()\n                headers = {**databricks_auth_headers, **headers}\n\n            return api_base, headers\n        except ImportError:\n            raise DatabricksException(\n                status_code=400,\n                message=(\n                    \"If the Databricks base URL and API key are not set, the databricks-sdk \"\n                    \"Python library must be installed. Please install the databricks-sdk, set \"\n                    \"{LLM_PROVIDER}_API_BASE and {LLM_PROVIDER}_API_KEY environment variables, \"\n                    \"or provide the base URL and API key as arguments.\"\n                ),\n            )\n\n    def databricks_validate_environment(\n        self,\n        api_key: str | None,\n        api_base: str | None,\n        endpoint_type: Literal[\"chat_completions\", \"embeddings\"],\n        custom_endpoint: bool | None,\n        headers: dict | None,\n        custom_user_agent: str | None = None,\n    ) -> tuple[str, dict]:","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/databricks/common_utils.py#L276-L312","documentation":"_get_databricks_credentials is the fallback when no explicit api_key/api_base is provided: it imports databricks.sdk WorkspaceClient (with litellm partner telemetry) to authenticate from the local profile. The ImportError is converted to DatabricksException(400). Note the literal '{LLM_PROVIDER}' placeholder ships un-formatted in the message — read it as DATABRICKS_API_BASE / DATABRICKS_API_KEY.","triggerScenarios":"databricks_validate_environment reached the SDK fallback (no api_key, no headers, custom_endpoint false) while databricks-sdk is not importable in the running interpreter — not installed, or installed in another venv.","commonSituations":"Slim Docker/CI images running litellm without the SDK; env vars misspelled (DATABRICKS_HOST instead of DATABRICKS_API_BASE) so the env path is skipped; SDK present in the build stage but pruned from the runtime image.","solutions":["pip install databricks-sdk into the exact environment that runs litellm","Or export DATABRICKS_API_KEY and DATABRICKS_API_BASE so the SDK fallback is never taken","Or pass api_key=/api_base= explicitly on the call or router deployment","Double-check env var spelling — only DATABRICKS_API_BASE/DATABRICKS_API_KEY are read on this path"],"exampleFix":"# before — SDK missing, no env vars\nlitellm.completion(model='databricks/my-model', messages=msgs)  # 400\n\n# after\n# pip install databricks-sdk\n# or:\nos.environ['DATABRICKS_API_BASE'] = 'https://adb-1234.0.azuredatabricks.net/serving-endpoints'\nos.environ['DATABRICKS_API_KEY'] = 'dapi...'\nlitellm.completion(model='databricks/my-model', messages=msgs)","handlingStrategy":"validation","validationCode":"import importlib.util, os\n\ndef databricks_auth_resolvable() -> bool:\n    env_ok = bool(os.getenv('DATABRICKS_API_KEY') and os.getenv('DATABRICKS_API_BASE'))\n    m2m_ok = all(os.getenv(k) for k in ('DATABRICKS_CLIENT_ID', 'DATABRICKS_CLIENT_SECRET', 'DATABRICKS_API_BASE'))\n    sdk_ok = importlib.util.find_spec('databricks') is not None\n    return env_ok or m2m_ok or sdk_ok\n\nif not databricks_auth_resolvable():\n    raise RuntimeError('no databricks auth path available: set env vars or install databricks-sdk')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bake databricks-sdk into the runtime image or always ship explicit env vars - never rely on the dev machine's SDK profile","Check for misspelled env var names (only DATABRICKS_API_BASE/DATABRICKS_API_KEY are read on this path)"],"tags":["databricks","dependencies","environment-variables","authentication"],"backgroundTag":"missing-sdk-dependency","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}