{"record":{"id":"74dedffeb6fcacc5","repo":"BerriAI/litellm","slug":"could-not-start-xai-oauth-callback-server-last-e","errorCode":null,"errorMessage":"Could not start xAI OAuth callback server: {last_error}","messagePattern":"Could not start xAI OAuth callback server: (.+?)","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":273,"sourceCode":"\n    def _pkce_pair(self) -> tuple[str, str]:\n        verifier: Final = base64.urlsafe_b64encode(secrets.token_bytes(32)).rstrip(b\"=\").decode()\n        challenge: Final = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b\"=\").decode()\n        return verifier, challenge\n\n    def _start_callback_server(self, state: str) -> tuple[_CallbackServer, str]:\n        last_error: OSError | None = None\n        for port in (XAI_OAUTH_REDIRECT_PORT, 0):\n            try:\n                server = _CallbackServer((XAI_OAUTH_REDIRECT_HOST, port), _CallbackHandler)\n                server.expected_state = state\n                server.callback_result = None\n                actual_port = server.server_address[1]\n                redirect_uri = f\"http://{XAI_OAUTH_REDIRECT_HOST}:{actual_port}{XAI_OAUTH_REDIRECT_PATH}\"\n                return server, redirect_uri\n            except OSError as exc:\n                last_error = exc\n        raise XAIOAuthError(f\"Could not start xAI OAuth callback server: {last_error}\")\n\n    def _build_authorize_url(\n        self,\n        authorization_endpoint: str,\n        redirect_uri: str,\n        challenge: str,\n        state: str,\n        nonce: str,\n    ) -> str:\n        params: Final = {\n            \"response_type\": \"code\",\n            \"client_id\": XAI_OAUTH_CLIENT_ID,\n            \"redirect_uri\": redirect_uri,\n            \"scope\": XAI_OAUTH_SCOPE,\n            \"code_challenge\": challenge,\n            \"code_challenge_method\": \"S256\",\n            \"state\": state,\n            \"nonce\": nonce,","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L255-L291","documentation":"XAIOAuthError raised after both attempts to bind the loopback OAuth callback HTTPServer (fixed port and ephemeral 0) failed with OSError: there is no redirect_uri to embed in the authorization URL, so login cannot start.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:273 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Free up the callback port or configure a different port; the error shows why the local server could not bind.","Check for firewall restrictions or another process already listening on the OAuth callback port."],"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"}