earendil-works/pi · error · Error

OpenRouter OAuth key exchange failed (HTTP ${response.status

Error message

OpenRouter OAuth key exchange failed (HTTP ${response.status})${detail ? `: ${detail}` : ""}

What it means

Error "OpenRouter OAuth key exchange failed (HTTP ${response.status})${detail ? `: ${detail}` : ""}" thrown in earendil-works/pi.

Source

Thrown at packages/ai/src/auth/oauth/openrouter.ts:120

		});
		try {
			const parsed = (await response.json()) as unknown;
			if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) body = parsed as JsonObject;
		} catch {
			if (response.ok) throw new Error("OpenRouter OAuth returned invalid JSON");
		}
	} catch (error) {
		if (signal.aborted) throw new Error("Login cancelled");
		if (controller.signal.aborted) throw new Error("OpenRouter OAuth token exchange timed out");
		throw error;
	} finally {
		clearTimeout(timeout);
		signal.removeEventListener("abort", onAbort);
	}

	if (!response.ok) {
		const detail = errorDetail(body);
		throw new Error(`OpenRouter OAuth key exchange failed (HTTP ${response.status})${detail ? `: ${detail}` : ""}`);
	}

	if (typeof body.key !== "string" || body.key.length === 0) {
		throw new Error('OpenRouter OAuth response carries no "key"');
	}

	return {
		type: "oauth",
		access: body.key,
		refresh: "",
		expires: Number.MAX_SAFE_INTEGER,
	};
}

async function startCallbackServer(
	callbackPath: string,
	verifier: string,
	signal: AbortSignal,

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Check the HTTP status and detail; verify the exchanged code is valid and unused.

When it happens

Trigger: Thrown at packages/ai/src/auth/oauth/openrouter.ts:120 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/2afe35a5aec3608f. Report an issue: GitHub.