BerriAI/litellm · error · DatabricksException

Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY en

Error message

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

What it means

Raised when DATABRICKS_API_BASE is not provided and LiteLLM tries to derive the workspace URL from the databricks-sdk package, but the import fails because databricks-sdk is not installed. The fix paths are mutually exclusive: either provide base+key explicitly or install the SDK.

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 6c2dcb801b)

Solutions

  1. Set DATABRICKS_API_BASE=https://<workspace-host>/serving-endpoints and DATABRICKS_API_KEY=<token>
  2. Or install the SDK: pip install databricks-sdk
  3. For containerized proxy deployments, prefer explicit env vars to avoid pulling in the SDK
  4. Pin databricks-sdk to a compatible version if SDK-based auth is required

Example fix

# before
# no env vars, no SDK installed

# after
export DATABRICKS_API_BASE="https://adb-1234567890.0.azuredatabricks.net/serving-endpoints"
export DATABRICKS_API_KEY="dapi..."
Defensive patterns

Strategy: validation

Validate before calling

if not os.getenv("DATABRICKS_API_BASE") and importlib.util.find_spec("databricks.sdk") is None:
    raise RuntimeError("Set DATABRICKS_API_BASE/_API_KEY or pip install databricks-sdk")

Try / catch

try:
    resp = litellm.completion(model="databricks/mymodel", messages=msgs)
except Exception as e:
    if "databricks-sdk" in str(e):
        raise ConfigError("Missing Databricks config: set DATABRICKS_API_BASE and DATABRICKS_API_KEY") from e
    raise

Prevention

When it happens

Trigger: Configuring a Databricks model without DATABRICKS_API_BASE/DATABRICKS_API_KEY env vars and without databricks-sdk in the Python environment (common in slim Docker images where the optional dependency was not included).

Common situations: Deploying LiteLLM proxy to a minimal container that excluded optional deps; local venv created from a requirements list that omitted databricks-sdk; CI environment differing from local.

Related errors


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