BerriAI/litellm · error · XAIOAuthError

Timed out waiting for xAI OAuth callback

Error message

Timed out waiting for xAI OAuth callback

What it means

XAIOAuthError raised when the loopback callback server sees no completed request before the deadline: the user never finished (or never saw) the authorization page, so login times out and must be re-attempted.

Source

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

            "scope": XAI_OAUTH_SCOPE,
            "code_challenge": challenge,
            "code_challenge_method": "S256",
            "state": state,
            "nonce": nonce,
        }
        return f"{authorization_endpoint}?{urlencode(params)}"

    def _wait_for_callback(self, server: _CallbackServer) -> dict[str, str | None]:
        server.timeout = 1
        deadline: Final = time.time() + XAI_OAUTH_CALLBACK_TIMEOUT_SECONDS
        try:
            while time.time() < deadline:
                server.handle_request()
                if server.callback_result is not None:
                    return server.callback_result
        finally:
            server.server_close()
        raise XAIOAuthError("Timed out waiting for xAI OAuth callback")

    def _exchange_token(self, token_endpoint: str, data: dict[str, str]) -> dict[str, Any]:
        try:
            response: Final = self._client().post(
                token_endpoint,
                headers={
                    "Accept": "application/json",
                    "Content-Type": "application/x-www-form-urlencoded",
                },
                data=data,
            )
            response.raise_for_status()
        except httpx.HTTPStatusError as exc:
            raise XAIOAuthError(
                f"xAI OAuth token request failed: {exc.response.status_code} {exc.response.text}"
            ) from exc
        try:
            body: Final = response.json()

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Complete the browser login promptly; the callback wait timed out.
  2. If the browser flow completed, check that the redirect reached localhost (no proxy/VPN blocking it) and retry.
Defensive patterns

Strategy: retry

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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