{"record":{"id":"a1f96f1ed2a576c9","repo":"BerriAI/litellm","slug":"timed-out-waiting-for-xai-oauth-callback","errorCode":null,"errorMessage":"Timed out waiting for xAI OAuth callback","messagePattern":"Timed out waiting for xAI OAuth callback","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":305,"sourceCode":"            \"scope\": XAI_OAUTH_SCOPE,\n            \"code_challenge\": challenge,\n            \"code_challenge_method\": \"S256\",\n            \"state\": state,\n            \"nonce\": nonce,\n        }\n        return f\"{authorization_endpoint}?{urlencode(params)}\"\n\n    def _wait_for_callback(self, server: _CallbackServer) -> dict[str, str | None]:\n        server.timeout = 1\n        deadline: Final = time.time() + XAI_OAUTH_CALLBACK_TIMEOUT_SECONDS\n        try:\n            while time.time() < deadline:\n                server.handle_request()\n                if server.callback_result is not None:\n                    return server.callback_result\n        finally:\n            server.server_close()\n        raise XAIOAuthError(\"Timed out waiting for xAI OAuth callback\")\n\n    def _exchange_token(self, token_endpoint: str, data: dict[str, str]) -> dict[str, Any]:\n        try:\n            response: Final = self._client().post(\n                token_endpoint,\n                headers={\n                    \"Accept\": \"application/json\",\n                    \"Content-Type\": \"application/x-www-form-urlencoded\",\n                },\n                data=data,\n            )\n            response.raise_for_status()\n        except httpx.HTTPStatusError as exc:\n            raise XAIOAuthError(\n                f\"xAI OAuth token request failed: {exc.response.status_code} {exc.response.text}\"\n            ) from exc\n        try:\n            body: Final = response.json()","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L287-L323","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:305 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Complete the browser login promptly; the callback wait timed out.","If the browser flow completed, check that the redirect reached localhost (no proxy/VPN blocking it) and retry."],"exampleFix":null,"handlingStrategy":"retry","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"}