{"record":{"id":"d42d7ad586f102fc","repo":"BerriAI/litellm","slug":"xai-authorization-failed-description","errorCode":null,"errorMessage":"xAI authorization failed: {description}","messagePattern":"xAI authorization failed: (.+?)","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":151,"sourceCode":"        server, redirect_uri = self._start_callback_server(state)\n        authorize_url: Final = self._build_authorize_url(\n            authorization_endpoint=discovery[\"authorization_endpoint\"],\n            redirect_uri=redirect_uri,\n            challenge=challenge,\n            state=state,\n            nonce=nonce,\n        )\n\n        if no_browser or not webbrowser.open(authorize_url):\n            sys.stdout.write(f\"Open this URL to authenticate with xAI:\\n{authorize_url}\\n\")\n            sys.stdout.flush()\n\n        result: Final = self._wait_for_callback(server)\n        if result.get(\"state\") != state:\n            raise XAIOAuthError(\"xAI OAuth state mismatch\")\n        if result.get(\"error\"):\n            description: Final = result.get(\"error_description\") or result[\"error\"]\n            raise XAIOAuthError(f\"xAI authorization failed: {description}\")\n        code: Final = result.get(\"code\")\n        if not code:\n            raise XAIOAuthError(\"xAI authorization failed: no code returned\")\n\n        token_payload: Final = self._exchange_token(\n            discovery[\"token_endpoint\"],\n            {\n                \"grant_type\": \"authorization_code\",\n                \"code\": code,\n                \"redirect_uri\": redirect_uri,\n                \"client_id\": XAI_OAUTH_CLIENT_ID,\n                \"code_verifier\": verifier,\n            },\n        )\n        auth_data: Final = self._build_auth_record(token_payload, discovery[\"token_endpoint\"])\n        self._write_auth_file(auth_data)\n        return auth_data\n","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L133-L169","documentation":"XAIOAuthError raised when the OAuth callback carried an 'error' field: the authorization server (or user denial) reported a failed consent, with error_description preferred over the bare error code in the message.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:151 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the error description in the message returned by xAI (e.g. access_denied) and address the cause.","Retry the login flow and approve the requested scopes in the xAI consent screen."],"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-14T00:17:10.932Z"}