earendil-works/pi · error · Error
Could not determine the OpenRouter OAuth callback port
Error message
Could not determine the OpenRouter OAuth callback port
What it means
Error "Could not determine the OpenRouter OAuth callback port" thrown in earendil-works/pi.
Source
Thrown at packages/ai/src/auth/oauth/openrouter.ts:228
server.listen(0, callbackHost, () => {
server.removeListener("error", reject);
resolve();
});
});
server.on("error", (error) => finish({ error }));
onAbort = () => finish({ error: new Error("Login cancelled") });
signal.addEventListener("abort", onAbort, { once: true });
if (signal.aborted) {
close();
throw new Error("Login cancelled");
}
timeout = setTimeout(() => finish({ error: new Error("OpenRouter OAuth login timed out") }), LOGIN_TIMEOUT_MS);
const address = server.address();
if (!address || typeof address === "string") {
close();
throw new Error("Could not determine the OpenRouter OAuth callback port");
}
return {
callbackUrl: `http://${callbackHost}:${address.port}${callbackPath}`,
close,
// A claimed callback is already exchanging its code; let that exchange settle the login.
cancelWait: () => {
if (!claimed) finish({ credential: null });
},
waitForCredential: () => credential,
};
}
async function loginOpenRouter(interaction: ProviderAuthInteraction): Promise<OAuthCredential> {
const { verifier, challenge } = await generatePKCE();
const callbackPath = `/oauth/callback/${crypto.randomUUID()}`;
const callback = await startCallbackServer(callbackPath, verifier, interaction.signal);
const manualAbort = new AbortController();View on GitHub (pinned to 4af9d21d3b)
Solutions
- Retry login; ensure a local loopback port can be bound for the OAuth callback.
When it happens
Trigger: Thrown at packages/ai/src/auth/oauth/openrouter.ts:228 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/f788274f0ac3a777.
Report an issue: GitHub.