earendil-works/pi · error
xAI OAuth returned invalid JSON (HTTP ${response.status})
Error message
xAI OAuth returned invalid JSON (HTTP ${response.status}) What it means
Error "xAI OAuth returned invalid JSON (HTTP ${response.status})" thrown in earendil-works/pi.
Source
Thrown at packages/ai/src/auth/oauth/xai.ts:91
body: new URLSearchParams(fields),
signal,
});
} catch (error) {
if (signal.aborted) {
throw new Error("Login cancelled");
}
throw error;
}
let body: JsonObject;
try {
const parsed = (await response.json()) as unknown;
body = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? (parsed as JsonObject) : {};
} catch {
if (signal.aborted) {
throw new Error("Login cancelled");
}
throw new Error(`xAI OAuth returned invalid JSON (HTTP ${response.status})`);
}
return {
ok: response.ok,
status: response.status,
body,
};
}
function requestFailure(action: string, response: OAuthHttpResponse): Error {
const error = typeof response.body.error === "string" ? response.body.error : undefined;
const description =
typeof response.body.error_description === "string" ? response.body.error_description : undefined;
const detail = [error, description].filter(Boolean).join(": ");
return new Error(`xAI OAuth ${action} failed (HTTP ${response.status})${detail ? `: ${detail}` : ""}`);
}
function parseDeviceCode(body: JsonObject): XaiDeviceCode {
// RFC 8628 allows interval 0 (no minimum wait); fall back to the poller'sView on GitHub (pinned to 4af9d21d3b)
Solutions
- Retry; check the HTTP status and the raw response body.
When it happens
Trigger: Thrown at packages/ai/src/auth/oauth/xai.ts:91 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/040a1e6f2780cb2a.
Report an issue: GitHub.