earendil-works/pi · error · Error
xAI OAuth device authorization failed
Error message
xAI OAuth device authorization failed (HTTP ${response.status})${detail ? `: ${detail}` : ""} What it means
HTTP failure of the xAI OAuth device-authorization request (POST to the device-code endpoint): the response status was not ok, and requestFailure composes this message from the status plus any error detail found in the body. The device-code flow cannot present a verification URI to the user, so login aborts; retrying is appropriate for transient 5xx/timeouts but not for client errors.
Solutions
- xAI device authorization failed; retry the OAuth flow and check the HTTP status detail.
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at packages/ai/src/auth/oauth/xai.ts:156 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/323f143d45f29d97.
Report an issue: GitHub.
Appendix: source
Thrown at packages/ai/src/auth/oauth/xai.ts:156
type: "oauth",
access,
refresh,
expires: Date.now() + expiresInSeconds * 1000 - REFRESH_SKEW_MS,
};
}
async function requestDeviceCode(signal: AbortSignal): Promise<XaiDeviceCode> {
const response = await postForm(
XAI_DEVICE_CODE_URL,
{
client_id: XAI_CLIENT_ID,
scope: XAI_SCOPE,
referrer: "pi",
},
signal,
);
if (!response.ok) {
throw requestFailure("device authorization", response);
}
return parseDeviceCode(response.body);
}
async function pollForTokens(device: XaiDeviceCode, signal: AbortSignal): Promise<OAuthCredential> {
return pollOAuthDeviceCodeFlow<OAuthCredential>({
intervalSeconds: device.intervalSeconds,
expiresInSeconds: device.expiresInSeconds,
waitBeforeFirstPoll: true,
signal,
poll: async () => {
const response = await postForm(
XAI_TOKEN_URL,
{
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
client_id: XAI_CLIENT_ID,
device_code: device.deviceCode,
},View on GitHub (pinned to 4af9d21d3b)