BerriAI/litellm · error · XAIOAuthLoginRequiredError

xAI OAuth login required. Run `litellm xai-oauth login`.

Error message

xAI OAuth login required. Run `litellm xai-oauth login`.

What it means

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.

Source

Thrown at litellm/llms/xai/oauth.py:99

class _CallbackServer(HTTPServer):
    expected_state: str
    callback_result: dict[str, str | None] | None


class XAIOAuthAuthenticator:
    def __init__(self, http_client: httpx.Client | HTTPHandler | None = None) -> None:
        self.token_dir = get_secret_str("XAI_OAUTH_TOKEN_DIR") or os.path.expanduser("~/.config/litellm/xai_oauth")
        self.auth_file = os.path.join(self.token_dir, get_secret_str("XAI_OAUTH_AUTH_FILE") or "auth.json")
        self.http_client = http_client

    def get_api_base(self) -> str:
        return get_secret_str("XAI_OAUTH_API_BASE") or get_secret_str("XAI_API_BASE") or XAI_API_BASE

    def get_access_token(self) -> str:
        auth_data: Final = self._read_auth_file()
        if not auth_data:
            raise XAIOAuthLoginRequiredError("xAI OAuth login required. Run `litellm xai-oauth login`.")

        access_token = auth_data.get("access_token")
        if access_token and not self._is_expired(auth_data):
            return access_token

        refresh_token: Final = auth_data.get("refresh_token")
        if not refresh_token:
            raise XAIOAuthLoginRequiredError("xAI OAuth refresh token missing. Run `litellm xai-oauth login`.")

        with _XAI_OAUTH_REFRESH_LOCK:
            locked_auth_data: Final = self._read_auth_file() or auth_data
            access_token = locked_auth_data.get("access_token")
            if access_token and not self._is_expired(locked_auth_data):
                return access_token

            refreshed: Final = self._refresh_tokens(locked_auth_data)
            return refreshed["access_token"]

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Run `litellm xai-oauth login` to complete the OAuth flow and store tokens.
  2. Alternatively use an xAI API key (XAI_API_KEY) instead of OAuth.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at litellm/llms/xai/oauth.py:99 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/e88aeec83b0e9b8f. Report an issue: GitHub.