earendil-works/pi · error · Error

xAI OAuth token refresh failed

Error message

xAI OAuth token refresh failed (HTTP ${response.status})${detail ? `: ${detail}` : ""}

What it means

HTTP failure of the xAI OAuth token refresh (POST grant_type=refresh_token): the token endpoint answered non-ok, and requestFailure formats the status plus optional body detail. The stored refresh token did not yield new credentials — commonly an expired/revoked token — so the caller (xaiOAuth) should not silently loop; re-authentication is needed for 4xx, retry for transient 5xx.

Solutions

  1. xAI token refresh failed; re-authenticate to obtain a new token.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at packages/ai/src/auth/oauth/xai.ts:224 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/7b1414d807c7b4fc. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/auth/oauth/xai.ts:224

		verificationUri: device.verificationUriComplete ?? device.verificationUri,
		intervalSeconds: device.intervalSeconds,
		expiresInSeconds: device.expiresInSeconds,
	});
	return pollForTokens(device, interaction.signal);
}

async function refreshXaiToken(refreshToken: string, signal: AbortSignal): Promise<OAuthCredential> {
	const response = await postForm(
		XAI_TOKEN_URL,
		{
			grant_type: "refresh_token",
			client_id: XAI_CLIENT_ID,
			refresh_token: refreshToken,
		},
		signal,
	);
	if (!response.ok) {
		throw requestFailure("token refresh", response);
	}
	return credentialsFromTokenResponse(response.body, refreshToken);
}

export const xaiOAuth: OAuthAuth = {
	name: "xAI (Grok/X subscription)",
	isSubscription: true,
	loginLabel: "Sign in with SuperGrok or X Premium",
	login: loginXai,
	refresh: (credential, signal) => refreshXaiToken(credential.refresh, signal),

	async toAuth(credential) {
		return { apiKey: credential.access };
	},
};

View on GitHub (pinned to 4af9d21d3b)