{"record":{"id":"e88aeec83b0e9b8f","repo":"BerriAI/litellm","slug":"xai-oauth-login-required-run-litellm-xai-oauth-l","errorCode":null,"errorMessage":"xAI OAuth login required. Run `litellm xai-oauth login`.","messagePattern":"xAI OAuth login required\\. Run `litellm xai-oauth login`\\.","errorType":"exception","errorClass":"XAIOAuthLoginRequiredError","httpStatus":null,"severity":"error","filePath":"litellm/llms/xai/oauth.py","lineNumber":99,"sourceCode":"\nclass _CallbackServer(HTTPServer):\n    expected_state: str\n    callback_result: dict[str, str | None] | None\n\n\nclass XAIOAuthAuthenticator:\n    def __init__(self, http_client: httpx.Client | HTTPHandler | None = None) -> None:\n        self.token_dir = get_secret_str(\"XAI_OAUTH_TOKEN_DIR\") or os.path.expanduser(\"~/.config/litellm/xai_oauth\")\n        self.auth_file = os.path.join(self.token_dir, get_secret_str(\"XAI_OAUTH_AUTH_FILE\") or \"auth.json\")\n        self.http_client = http_client\n\n    def get_api_base(self) -> str:\n        return get_secret_str(\"XAI_OAUTH_API_BASE\") or get_secret_str(\"XAI_API_BASE\") or XAI_API_BASE\n\n    def get_access_token(self) -> str:\n        auth_data: Final = self._read_auth_file()\n        if not auth_data:\n            raise XAIOAuthLoginRequiredError(\"xAI OAuth login required. Run `litellm xai-oauth login`.\")\n\n        access_token = auth_data.get(\"access_token\")\n        if access_token and not self._is_expired(auth_data):\n            return access_token\n\n        refresh_token: Final = auth_data.get(\"refresh_token\")\n        if not refresh_token:\n            raise XAIOAuthLoginRequiredError(\"xAI OAuth refresh token missing. Run `litellm xai-oauth login`.\")\n\n        with _XAI_OAUTH_REFRESH_LOCK:\n            locked_auth_data: Final = self._read_auth_file() or auth_data\n            access_token = locked_auth_data.get(\"access_token\")\n            if access_token and not self._is_expired(locked_auth_data):\n                return access_token\n\n            refreshed: Final = self._refresh_tokens(locked_auth_data)\n            return refreshed[\"access_token\"]\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/xai/oauth.py#L81-L117","documentation":"XAIOAuthLoginRequiredError from get_access_token: the stored xAI OAuth auth file is missing/empty (or lacks a usable token), so no cached credential exists. The message directs the user to the interactive login command that creates it.","triggerScenarios":"Thrown at litellm/llms/xai/oauth.py:99 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run `litellm xai-oauth login` to complete the OAuth flow and store tokens.","Alternatively use an xAI API key (XAI_API_KEY) instead of OAuth."],"exampleFix":null,"handlingStrategy":"fallback","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"}