{"record":{"id":"80bdad01b642689e","repo":"BerriAI/litellm","slug":"either-set-the-databricks-api-base-and-databricks","errorCode":null,"errorMessage":"Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY environment variables, or install the databricks-sdk Python library.","messagePattern":"Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY environment variables, or install the databricks-sdk Python library\\.","errorType":"exception","errorClass":"DatabricksException","httpStatus":400,"severity":"error","filePath":"litellm/llms/databricks/common_utils.py","lineNumber":193,"sourceCode":"\n        # Default: just litellm\n        return f\"litellm/{version}\"\n\n    def _get_api_base(self, api_base: str | None) -> str:\n        \"\"\"\n        Get the Databricks API base URL.\n\n        If not provided, attempts to get it from the Databricks SDK.\n        \"\"\"\n        if api_base is None:\n            try:\n                from databricks.sdk import WorkspaceClient\n\n                databricks_client: Final = WorkspaceClient()\n                api_base = f\"{databricks_client.config.host}/serving-endpoints\"\n                return api_base\n            except ImportError:\n                raise DatabricksException(\n                    status_code=400,\n                    message=(\n                        \"Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY environment variables, \"\n                        \"or install the databricks-sdk Python library.\"\n                    ),\n                )\n        return api_base\n\n    def _get_oauth_m2m_token(\n        self,\n        api_base: str,\n        client_id: str,\n        client_secret: str,\n    ) -> str:\n        \"\"\"\n        Obtain an OAuth M2M access token using client credentials flow.\n\n        This is the recommended authentication method for production integrations","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/databricks/common_utils.py#L175-L211","documentation":"DatabricksProvider.get_api_base was asked for the API base but none was supplied, so it tried to import databricks.sdk.WorkspaceClient to derive '<host>/serving-endpoints' from your Databricks CLI/SDK profile. The import failed because databricks-sdk is not installed, raising DatabricksException(400) that tells you to either set DATABRICKS_API_BASE/DATABRICKS_API_KEY or install the SDK.","triggerScenarios":"litellm.completion(model='databricks/...', ...) with no api_base argument, no DATABRICKS_API_BASE env var, and no databricks-sdk package in the interpreter running litellm (slim Docker image, CI runner, minimal venv).","commonSituations":"pip install litellm in a slim container without the databricks extra; SDK installed into a different virtualenv than the one running the app; CI caching a requirements set that dropped databricks-sdk.","solutions":["pip install databricks-sdk in the exact environment that runs litellm","Or export DATABRICKS_API_BASE=https://<workspace-host>/serving-endpoints and DATABRICKS_API_KEY=<token> so no SDK is needed","Or pass api_base= (and api_key=) explicitly on the call or in the router deployment"],"exampleFix":"# before — no env vars, SDK missing\nlitellm.completion(model='databricks/databricks-dbrx-instruct', messages=msgs)  # 400\n\n# after — option A: install the SDK\n# pip install databricks-sdk\n\n# after — option B: set env vars instead\nimport os\nos.environ['DATABRICKS_API_BASE'] = 'https://adb-1234567890.0.azuredatabricks.net/serving-endpoints'\nos.environ['DATABRICKS_API_KEY'] = 'dapi...'\nlitellm.completion(model='databricks/databricks-dbrx-instruct', messages=msgs)","handlingStrategy":"validation","validationCode":"import importlib.util, os\n\ndef databricks_config_ready() -> bool:\n    env_ok = bool(os.getenv('DATABRICKS_API_BASE') and os.getenv('DATABRICKS_API_KEY'))\n    sdk_ok = importlib.util.find_spec('databricks') is not None\n    return env_ok or sdk_ok\n\nif not databricks_config_ready():\n    raise RuntimeError('install databricks-sdk or set DATABRICKS_API_BASE/DATABRICKS_API_KEY')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add databricks-sdk to the same requirements set as litellm for any image that calls databricks models","Run a startup config check for env vars vs SDK availability and fail fast"],"tags":["databricks","dependencies","environment-variables","setup"],"backgroundTag":"missing-sdk-dependency","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}