BerriAI/litellm · error · DatabricksException

Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY…

Error message

Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY environment variables, or install the databricks-sdk Python library.

What it means

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.

Solutions

  1. pip install databricks-sdk in the exact environment that runs litellm
  2. Or export DATABRICKS_API_BASE=https://<workspace-host>/serving-endpoints and DATABRICKS_API_KEY=<token> so no SDK is needed
  3. Or pass api_base= (and api_key=) explicitly on the call or in the router deployment

Example fix

# before — no env vars, SDK missing
litellm.completion(model='databricks/databricks-dbrx-instruct', messages=msgs)  # 400

# after — option A: install the SDK
# pip install databricks-sdk

# after — option B: set env vars instead
import os
os.environ['DATABRICKS_API_BASE'] = 'https://adb-1234567890.0.azuredatabricks.net/serving-endpoints'
os.environ['DATABRICKS_API_KEY'] = 'dapi...'
litellm.completion(model='databricks/databricks-dbrx-instruct', messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util, os

def databricks_config_ready() -> bool:
    env_ok = bool(os.getenv('DATABRICKS_API_BASE') and os.getenv('DATABRICKS_API_KEY'))
    sdk_ok = importlib.util.find_spec('databricks') is not None
    return env_ok or sdk_ok

if not databricks_config_ready():
    raise RuntimeError('install databricks-sdk or set DATABRICKS_API_BASE/DATABRICKS_API_KEY')

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/80bdad01b642689e. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/databricks/common_utils.py:193

        # Default: just litellm
        return f"litellm/{version}"

    def _get_api_base(self, api_base: str | None) -> str:
        """
        Get the Databricks API base URL.

        If not provided, attempts to get it from the Databricks SDK.
        """
        if api_base is None:
            try:
                from databricks.sdk import WorkspaceClient

                databricks_client: Final = WorkspaceClient()
                api_base = f"{databricks_client.config.host}/serving-endpoints"
                return api_base
            except ImportError:
                raise DatabricksException(
                    status_code=400,
                    message=(
                        "Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY environment variables, "
                        "or install the databricks-sdk Python library."
                    ),
                )
        return api_base

    def _get_oauth_m2m_token(
        self,
        api_base: str,
        client_id: str,
        client_secret: str,
    ) -> str:
        """
        Obtain an OAuth M2M access token using client credentials flow.

        This is the recommended authentication method for production integrations

View on GitHub (pinned to 77b7c6c40c)