BerriAI/litellm · error · XAIOAuthError

xAI OAuth discovery request failed

Error message

xAI OAuth discovery request failed: {exc.response.status_code} {exc.response.text}

What it means

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.

Solutions

  1. Check the status code and body in the error; the OIDC discovery document request failed (network or endpoint issue).
  2. Verify network access to the xAI identity endpoint and retry.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at litellm/llms/xai/oauth.py:233 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/llms/xai/oauth.py:233

            except OSError:
                pass
            raise

    def _is_expired(self, auth_data: dict[str, Any]) -> bool:
        expires_at: Final = auth_data.get("expires_at")
        if expires_at is None:
            return True
        try:
            return time.time() >= float(expires_at) - XAI_OAUTH_EXPIRY_SKEW_SECONDS
        except (TypeError, ValueError):
            return True

    def _discover(self) -> dict[str, str]:
        try:
            response: Final = self._client().get(XAI_OAUTH_DISCOVERY_URL, headers={"Accept": "application/json"})
            response.raise_for_status()
        except httpx.HTTPStatusError as exc:
            raise XAIOAuthError(
                f"xAI OAuth discovery request failed: {exc.response.status_code} {exc.response.text}"
            ) from exc
        try:
            data: Final = response.json()
        except ValueError as exc:
            raise XAIOAuthError("xAI OAuth discovery response was not valid JSON") from exc
        authorization_endpoint: Final = data.get("authorization_endpoint")
        token_endpoint: Final = data.get("token_endpoint")
        if not authorization_endpoint or not token_endpoint:
            raise XAIOAuthError("xAI OAuth discovery missing endpoints")
        return {
            "authorization_endpoint": self._validate_xai_endpoint(authorization_endpoint),
            "token_endpoint": self._validate_xai_endpoint(token_endpoint),
        }

    def _validate_xai_endpoint(self, url: str) -> str:
        parsed: Final = urlparse(url)
        host: Final = (parsed.hostname or "").lower()

View on GitHub (pinned to 77b7c6c40c)