BerriAI/litellm · error · DatabricksException

Missing API Key - A call is being made to LLM Provider but…

Error message

Missing API Key - A call is being made to LLM Provider but no key is set either in the environment variables ({LLM_PROVIDER}_API_KEY) or via params

What it means

databricks_validate_environment saw an api_base (or custom_endpoint=True) but no api_key, no auth headers, and no client_id/secret pair. For custom endpoints LiteLLM deliberately does not fall back to the SDK, so it raises 400 'Missing API Key'. The '{LLM_PROVIDER}' placeholder in the shipped text stands in for DATABRICKS.

Solutions

  1. Pass the key: add api_key='dapi...' to the call or the deployment's litellm_params
  2. Or export DATABRICKS_API_KEY in the proxy/server process environment
  3. If M2M was intended, set DATABRICKS_CLIENT_ID + DATABRICKS_CLIENT_SECRET + DATABRICKS_API_BASE instead
  4. If header-based auth was intended, supply an Authorization header so the headers dict is non-empty

Example fix

# before — api_base only
litellm.completion(model='databricks/my-endpoint', messages=msgs,
                  api_base='https://host/serving-endpoints')  # 400 Missing API Key

# after
litellm.completion(
    model='databricks/my-endpoint', messages=msgs,
    api_base='https://host/serving-endpoints',
    api_key=os.environ['DATABRICKS_API_KEY'],
)
Defensive patterns

Strategy: validation

Validate before calling

import os

def custom_endpoint_auth_ok(api_base: str | None, api_key: str | None) -> bool:
    if api_base is None:
        return True  # SDK fallback path applies
    return bool(api_key or os.getenv('DATABRICKS_API_KEY'))

if not custom_endpoint_auth_ok(cfg.get('api_base'), cfg.get('api_key')):
    raise RuntimeError('custom databricks endpoint requires api_key or DATABRICKS_API_KEY')

Prevention

When it happens

Trigger: A custom LLM deployment/route pointing at a Databricks URL where api_base was supplied (or custom_endpoint flagged) but api_key was not passed and DATABRICKS_API_KEY is unset; proxy config with litellm_params: api_base only; per-call api_key dropped in a refactor.

Common situations: litellm_config.yaml deployment missing the api_key field; key stored under a differently-named env var; custom gateway setups where the key was expected to come from headers that were never set.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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

Appendix: source

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

        # Check for OAuth M2M credentials (recommended for production)
        client_id: Final = os.getenv("DATABRICKS_CLIENT_ID")
        client_secret: Final = os.getenv("DATABRICKS_CLIENT_SECRET")

        # Determine api_base first
        if api_base is None:
            api_base = os.getenv("DATABRICKS_API_BASE")

        if client_id and client_secret and api_base:
            # Use OAuth M2M flow (preferred for production)
            verbose_logger.debug("Using OAuth M2M authentication for Databricks")
            access_token: Final = self._get_oauth_m2m_token(api_base, client_id, client_secret)
            headers = headers or {}
            headers["Authorization"] = f"Bearer {access_token}"
            headers["Content-Type"] = "application/json"
        elif api_key is None and not headers:
            if custom_endpoint is True:
                raise DatabricksException(
                    status_code=400,
                    message="Missing API Key - A call is being made to LLM Provider but no key is set either in the environment variables ({LLM_PROVIDER}_API_KEY) or via params",
                )
            else:
                # Fallback to Databricks SDK (registers partner telemetry)
                verbose_logger.debug("Using Databricks SDK for authentication")
                api_base, headers = self._get_databricks_credentials(
                    api_base=api_base, api_key=api_key, headers=headers
                )

        if api_base is None:
            if custom_endpoint:
                raise DatabricksException(
                    status_code=400,
                    message="Missing API Base - A call is being made to LLM Provider but no api base is set either in the environment variables ({LLM_PROVIDER}_API_KEY) or via params",
                )
            else:
                api_base, headers = self._get_databricks_credentials(

View on GitHub (pinned to 77b7c6c40c)