BerriAI/litellm · error · DatabricksException

If the Databricks base URL and API key are not set, the…

Error message

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.

What it means

_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.

Solutions

  1. pip install databricks-sdk into the exact environment that runs litellm
  2. Or export DATABRICKS_API_KEY and DATABRICKS_API_BASE so the SDK fallback is never taken
  3. Or pass api_key=/api_base= explicitly on the call or router deployment
  4. Double-check env var spelling — only DATABRICKS_API_BASE/DATABRICKS_API_KEY are read on this path

Example fix

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

# after
# pip install databricks-sdk
# or:
os.environ['DATABRICKS_API_BASE'] = 'https://adb-1234.0.azuredatabricks.net/serving-endpoints'
os.environ['DATABRICKS_API_KEY'] = 'dapi...'
litellm.completion(model='databricks/my-model', messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util, os

def databricks_auth_resolvable() -> bool:
    env_ok = bool(os.getenv('DATABRICKS_API_KEY') and os.getenv('DATABRICKS_API_BASE'))
    m2m_ok = all(os.getenv(k) for k in ('DATABRICKS_CLIENT_ID', 'DATABRICKS_CLIENT_SECRET', 'DATABRICKS_API_BASE'))
    sdk_ok = importlib.util.find_spec('databricks') is not None
    return env_ok or m2m_ok or sdk_ok

if not databricks_auth_resolvable():
    raise RuntimeError('no databricks auth path available: set env vars or install databricks-sdk')

Prevention

When it happens

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

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

Related errors


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

Appendix: source

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

        """
        headers = headers or {"Content-Type": "application/json"}
        try:
            from databricks.sdk import WorkspaceClient, useragent

            # Register LiteLLM as partner for Databricks telemetry attribution
            useragent.with_partner("litellm")

            databricks_client: Final = WorkspaceClient()

            api_base = api_base or f"{databricks_client.config.host}/serving-endpoints"

            if api_key is None:
                databricks_auth_headers: Final[dict[str, str]] = databricks_client.config.authenticate()
                headers = {**databricks_auth_headers, **headers}

            return api_base, headers
        except ImportError:
            raise DatabricksException(
                status_code=400,
                message=(
                    "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."
                ),
            )

    def databricks_validate_environment(
        self,
        api_key: str | None,
        api_base: str | None,
        endpoint_type: Literal["chat_completions", "embeddings"],
        custom_endpoint: bool | None,
        headers: dict | None,
        custom_user_agent: str | None = None,
    ) -> tuple[str, dict]:

View on GitHub (pinned to 77b7c6c40c)