BerriAI/litellm · error · DatabricksException
Missing API Key - A call is being made to LLM Provider but n
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
Raised when a Databricks call is configured as a custom endpoint (custom_endpoint=True), no OAuth client credentials are present, no api_key is given, and no headers were supplied — so no authentication material exists at all. LiteLLM refuses the call with a 400 rather than sending an unauthenticated request.
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 6c2dcb801b)
Solutions
- Set DATABRICKS_API_KEY (or the provider-prefixed variant) in the environment
- Or pass api_key directly in the call / litellm_params
- If the gateway uses a custom header, pass explicit headers with the Authorization entry
- Verify the env var name matches the provider prefix LiteLLM expects
Example fix
# before response = litellm.completion(model="databricks/custom-model", messages=msgs, api_base=GW_URL) # after response = litellm.completion(model="databricks/custom-model", messages=msgs, api_base=GW_URL, api_key=os.environ["DATABRICKS_API_KEY"])
Defensive patterns
Strategy: validation
Validate before calling
if custom_endpoint and not (api_key or headers or os.getenv("DATABRICKS_API_KEY")):
raise RuntimeError("Custom Databricks endpoint requires an API key or explicit auth headers") Try / catch
try:
resp = litellm.completion(model=m, messages=msgs, api_base=gw_url)
except Exception as e:
if "Missing API Key" in str(e):
raise ConfigError("Provide the gateway/API key for the custom endpoint") from e
raise Prevention
- When routing Databricks models through a gateway, store the gateway key in litellm_params, not ambient env
- Add a preflight check that every custom-endpoint model declares an auth source
When it happens
Trigger: Using a custom/ai-gateway Databricks endpoint (custom endpoint flag set) while DATABRICKS_API_KEY and api_key are both absent and no Authorization header is passed manually.
Common situations: Pointing Databricks models at an internal AI gateway that requires its own key, but the key env var was never wired in; migrating config where api_base was updated but api_key was dropped.
Related errors
- Either set the DATABRICKS_API_BASE and DATABRICKS_API_KEY en
- If the Databricks base URL and API key are not set, the data
- Missing API Base - A call is being made to LLM Provider but
- 'username' is required in litellm_params when auth_mode='cp4
- Missing Azure Document Intelligence API Key - Set AZURE_DOCU
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/ecd841f4b9463ca5.
Report an issue: GitHub.