earendil-works/pi · error · Error

Invalid Copilot token response

Error message

Invalid Copilot token response

What it means

Error "Invalid Copilot token response" thrown in earendil-works/pi.

Source

Thrown at packages/ai/src/auth/oauth/github-copilot.ts:331

async function refreshGitHubCopilotAccessToken(
	refreshToken: string,
	enterpriseDomain: string | undefined,
	signal: AbortSignal,
): Promise<OAuthCredential> {
	const domain = enterpriseDomain || "github.com";
	const urls = getUrls(domain);

	const raw = await fetchJson(urls.copilotTokenUrl, {
		headers: {
			Accept: "application/json",
			Authorization: `Bearer ${refreshToken}`,
			...COPILOT_HEADERS,
		},
		signal,
	});

	if (!raw || typeof raw !== "object") {
		throw new Error("Invalid Copilot token response");
	}

	const token = (raw as Record<string, unknown>).token;
	const expiresAt = (raw as Record<string, unknown>).expires_at;

	if (typeof token !== "string" || typeof expiresAt !== "number") {
		throw new Error("Invalid Copilot token response fields");
	}

	return {
		type: "oauth",
		refresh: refreshToken,
		access: token,
		expires: expiresAt * 1000 - 5 * 60 * 1000,
		enterpriseUrl: enterpriseDomain,
	};
}

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Retry the Copilot token exchange; validate the response shape.

When it happens

Trigger: Thrown at packages/ai/src/auth/oauth/github-copilot.ts:331 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/dd73fdee9a7a232a. Report an issue: GitHub.