{"record":{"id":"5ca8816a7877f8c9","repo":"BerriAI/litellm","slug":"oauth-m2m-token-request-failed-e","errorCode":null,"errorMessage":"OAuth M2M token request failed: {e}","messagePattern":"OAuth M2M token request failed: (.+?)","errorType":"http","errorClass":"DatabricksException","httpStatus":500,"severity":"error","filePath":"litellm/llms/databricks/common_utils.py","lineNumber":246,"sourceCode":"        workspace_url = api_base.rstrip(\"/\")\n        if \"/serving-endpoints\" in workspace_url:\n            workspace_url = workspace_url.replace(\"/serving-endpoints\", \"\")\n\n        token_url: Final = f\"{workspace_url}/oidc/v1/token\"\n\n        try:\n            response: Final = requests.post(\n                token_url,\n                data={\n                    \"grant_type\": \"client_credentials\",\n                    \"scope\": \"all-apis\",\n                },\n                auth=(client_id, client_secret),\n                headers={\"Content-Type\": \"application/x-www-form-urlencoded\"},\n                timeout=30,\n            )\n        except requests.RequestException as e:\n            raise DatabricksException(\n                status_code=500,\n                message=f\"OAuth M2M token request failed: {e}\",\n            )\n\n        if response.status_code != 200:\n            raise DatabricksException(\n                status_code=response.status_code,\n                message=f\"OAuth M2M token request failed: {response.text}\",\n            )\n\n        token_data: Final = response.json()\n        return token_data[\"access_token\"]\n\n    def _get_databricks_credentials(\n        self, api_key: str | None, api_base: str | None, headers: dict | None\n    ) -> tuple[str, dict]:\n        \"\"\"\n        Get Databricks credentials using the Databricks SDK.","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/databricks/common_utils.py#L228-L264","documentation":"Raised when the HTTP POST to the Databricks OAuth machine-to-machine token endpoint itself fails at the transport level (requests.RequestException: connection refused, DNS failure, TLS error, timeout after 30s). LiteLLM wraps it as DatabricksException with status_code 500 and the underlying requests error text.","triggerScenarios":"OAuth M2M auth (client_id + client_secret + api_base set) and the token request to <host>/oidc/v1/token cannot connect: network egress blocked, wrong workspace host, firewall/proxy interference, or the 30s timeout exceeded.","commonSituations":"Containers without outbound internet/OAuth endpoint access; on-prem proxy not configured for requests (missing HTTPS_PROXY); typo in DATABRICKS_API_BASE host; DNS resolution failures in Kubernetes pods.","solutions":["Check the underlying requests error in the message (DNS/timeouts point to network, TLS errors to proxies)","Verify the workspace host in api_base is reachable: curl https://<host>/oidc/v1/token","Configure HTTPS_PROXY/HTTP_PROXY if the environment requires an egress proxy","Increase robustness with a retry, but fix root network cause first"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import socket, urllib.parse\nhost = urllib.parse.urlparse(api_base).hostname or \"\"\nassert host and socket.gethostbyname(host), \"workspace host unresolvable\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=m, messages=msgs)\nexcept Exception as e:\n    if \"OAuth M2M token request failed\" in str(e):\n        resp = backoff_retry(lambda: litellm.completion(model=m, messages=msgs), max_attempts=3)\n    else:\n        raise","preventionTips":["Verify egress from the runtime to the workspace OAuth endpoint before deploying","Set HTTPS_PROXY in proxy-required environments so requests can reach the token URL","Distinguish transport failures (this error) from credential rejections (non-200 variant) in your handling"],"tags":["databricks","oauth","network","authentication"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}