earendil-works/pi · error · Error
Anthropic OAuth is only available in Node.js environments
Error message
Anthropic OAuth is only available in Node.js environments
What it means
getNodeApis lazily loads Node's http modules to host the OAuth callback server; this sentinel fires when that lazy load is unavailable, i.e. the code is running outside a Node.js runtime (browser/edge) where those APIs do not exist.
Solutions
- Run Anthropic OAuth login in a Node.js environment, not a browser or edge runtime.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/ai/src/auth/oauth/anthropic.ts:42 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/9fcdf77be7dbce7b.
Report an issue: GitHub.
Appendix: source
Thrown at packages/ai/src/auth/oauth/anthropic.ts:42
let nodeApis: NodeApis | null = null;
let nodeApisPromise: Promise<NodeApis> | null = null;
const decode = (s: string) => atob(s);
const CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
const AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
const TOKEN_URL = "https://platform.claude.com/v1/oauth/token";
const CALLBACK_HOST = getProviderEnvValue("PI_OAUTH_CALLBACK_HOST") || "127.0.0.1";
const CALLBACK_PORT = 53692;
const CALLBACK_PATH = "/callback";
const REDIRECT_URI = `http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}`;
const SCOPES =
"org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload";
async function getNodeApis(): Promise<NodeApis> {
if (nodeApis) return nodeApis;
if (!nodeApisPromise) {
if (typeof process === "undefined" || (!process.versions?.node && !process.versions?.bun)) {
throw new Error("Anthropic OAuth is only available in Node.js environments");
}
nodeApisPromise = import("node:http").then((httpModule) => ({
createServer: httpModule.createServer,
}));
}
nodeApis = await nodeApisPromise;
return nodeApis;
}
function parseAuthorizationInput(input: string): { code?: string; state?: string } {
const value = input.trim();
if (!value) return {};
try {
const url = new URL(value);
return {
code: url.searchParams.get("code") ?? undefined,
state: url.searchParams.get("state") ?? undefined,View on GitHub (pinned to 4af9d21d3b)