{"record":{"id":"3ed4e94e804c044b","repo":"BerriAI/litellm","slug":"xai-oauth-discovery-request-failed-exc-response","errorCode":null,"errorMessage":"xAI OAuth discovery request failed: {exc.response.status_code} {exc.response.text}","messagePattern":"xAI OAuth discovery request failed: (.+?) (.+?)","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":233,"sourceCode":"            except OSError:\n                pass\n            raise\n\n    def _is_expired(self, auth_data: dict[str, Any]) -> bool:\n        expires_at: Final = auth_data.get(\"expires_at\")\n        if expires_at is None:\n            return True\n        try:\n            return time.time() >= float(expires_at) - XAI_OAUTH_EXPIRY_SKEW_SECONDS\n        except (TypeError, ValueError):\n            return True\n\n    def _discover(self) -> dict[str, str]:\n        try:\n            response: Final = self._client().get(XAI_OAUTH_DISCOVERY_URL, headers={\"Accept\": \"application/json\"})\n            response.raise_for_status()\n        except httpx.HTTPStatusError as exc:\n            raise XAIOAuthError(\n                f\"xAI OAuth discovery request failed: {exc.response.status_code} {exc.response.text}\"\n            ) from exc\n        try:\n            data: Final = response.json()\n        except ValueError as exc:\n            raise XAIOAuthError(\"xAI OAuth discovery response was not valid JSON\") from exc\n        authorization_endpoint: Final = data.get(\"authorization_endpoint\")\n        token_endpoint: Final = data.get(\"token_endpoint\")\n        if not authorization_endpoint or not token_endpoint:\n            raise XAIOAuthError(\"xAI OAuth discovery missing endpoints\")\n        return {\n            \"authorization_endpoint\": self._validate_xai_endpoint(authorization_endpoint),\n            \"token_endpoint\": self._validate_xai_endpoint(token_endpoint),\n        }\n\n    def _validate_xai_endpoint(self, url: str) -> str:\n        parsed: Final = urlparse(url)\n        host: Final = (parsed.hostname or \"\").lower()","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L215-L251","documentation":"XAIOAuthError wrapping an httpx.HTTPStatusError from the OIDC discovery GET: the xAI discovery document request was rejected, and the upstream status code and body are surfaced to explain why endpoint discovery failed.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:233 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the status code and body in the error; the OIDC discovery document request failed (network or endpoint issue).","Verify network access to the xAI identity endpoint and retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}