BerriAI/litellm · error · XAIOAuthError

xAI OAuth discovery missing endpoints

Error message

xAI OAuth discovery missing endpoints

What it means

Validation after fetching the xAI OAuth discovery document: the JSON parsed but is missing required endpoint URLs (authorization/token), so the OAuth flow cannot proceed. Indicates an unexpected discovery response shape from the discovery URL.

Source

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

        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()
        if parsed.scheme != "https" or (host != "x.ai" and not host.endswith(".x.ai")):
            raise XAIOAuthError(f"xAI OAuth discovery returned unexpected endpoint: {url}")
        return url

    def _pkce_pair(self) -> tuple[str, str]:
        verifier: Final = base64.urlsafe_b64encode(secrets.token_bytes(32)).rstrip(b"=").decode()
        challenge: Final = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b"=").decode()
        return verifier, challenge

    def _start_callback_server(self, state: str) -> tuple[_CallbackServer, str]:

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Verify the xAI OIDC discovery document still advertises the authorization and token endpoints; the provider config may have changed.
  2. Upgrade litellm to a version matching the current xAI OAuth configuration.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/llms/xai/oauth.py:243 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/2b8a6f7d228232f4. Report an issue: GitHub.