{"record":{"id":"2b8a6f7d228232f4","repo":"BerriAI/litellm","slug":"xai-oauth-discovery-missing-endpoints","errorCode":null,"errorMessage":"xAI OAuth discovery missing endpoints","messagePattern":"xAI OAuth discovery missing endpoints","errorType":"exception","errorClass":"XAIOAuthError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":243,"sourceCode":"        except (TypeError, ValueError):\n            return True\n\n    def _discover(self) -> dict[str, str]:\n        try:\n            response: Final = self._client().get(XAI_OAUTH_DISCOVERY_URL, headers={\"Accept\": \"application/json\"})\n            response.raise_for_status()\n        except httpx.HTTPStatusError as exc:\n            raise XAIOAuthError(\n                f\"xAI OAuth discovery request failed: {exc.response.status_code} {exc.response.text}\"\n            ) from exc\n        try:\n            data: Final = response.json()\n        except ValueError as exc:\n            raise XAIOAuthError(\"xAI OAuth discovery response was not valid JSON\") from exc\n        authorization_endpoint: Final = data.get(\"authorization_endpoint\")\n        token_endpoint: Final = data.get(\"token_endpoint\")\n        if not authorization_endpoint or not token_endpoint:\n            raise XAIOAuthError(\"xAI OAuth discovery missing endpoints\")\n        return {\n            \"authorization_endpoint\": self._validate_xai_endpoint(authorization_endpoint),\n            \"token_endpoint\": self._validate_xai_endpoint(token_endpoint),\n        }\n\n    def _validate_xai_endpoint(self, url: str) -> str:\n        parsed: Final = urlparse(url)\n        host: Final = (parsed.hostname or \"\").lower()\n        if parsed.scheme != \"https\" or (host != \"x.ai\" and not host.endswith(\".x.ai\")):\n            raise XAIOAuthError(f\"xAI OAuth discovery returned unexpected endpoint: {url}\")\n        return url\n\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]:","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L225-L261","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:243 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the xAI OIDC discovery document still advertises the authorization and token endpoints; the provider config may have changed.","Upgrade litellm to a version matching the current xAI OAuth configuration."],"exampleFix":null,"handlingStrategy":"validation","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"}