BerriAI/litellm · error · XAIOAuthError
xAI OAuth token response missing access_token
Error message
xAI OAuth token response missing access_token
What it means
XAIOAuthError raised in _build_auth_record when the token payload contains no access_token: the exchange response parsed fine but is unusable for authenticated API calls, so the auth record is not persisted.
Source
Thrown at litellm/llms/xai/oauth.py:339
) from exc
try:
body: Final = response.json()
except ValueError as exc:
raise XAIOAuthError("xAI OAuth token response was not valid JSON") from exc
if not isinstance(body, dict):
raise XAIOAuthError("xAI OAuth token response was not an object")
return body
def _build_auth_record(
self,
token_payload: dict[str, Any],
token_endpoint: str,
fallback_refresh_token: str | None = None,
) -> dict[str, Any]:
access_token: Final = token_payload.get("access_token")
refresh_token: Final = token_payload.get("refresh_token") or fallback_refresh_token
if not access_token:
raise XAIOAuthError("xAI OAuth token response missing access_token")
if not refresh_token:
raise XAIOAuthError("xAI OAuth token response missing refresh_token")
expires_in: Final = token_payload.get("expires_in") or 3600
try:
expires_at = int(time.time() + int(expires_in))
except (TypeError, ValueError):
expires_at = int(time.time() + 3600)
return {
"access_token": access_token,
"refresh_token": refresh_token,
"id_token": token_payload.get("id_token"),
"token_type": token_payload.get("token_type") or "Bearer",
"token_endpoint": token_endpoint,
"expires_at": expires_at,
}
def _refresh_tokens(self, auth_data: dict[str, Any]) -> dict[str, Any]:
token_endpoint = auth_data.get("token_endpoint")View on GitHub (pinned to 77b7c6c40c)
Solutions
- Restart the login flow; the token response lacked access_token, which usually means the grant failed.
- Verify the requested scopes and client configuration with xAI.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/llms/xai/oauth.py:339 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/a11bcaebc98c63a8.
Report an issue: GitHub.