earendil-works/pi · error · Error
Token exchange request failed. url=${TOKEN_URL}; redirect_ur
Error message
Token exchange request failed. url=${TOKEN_URL}; redirect_uri=${redirectUri}; response_type=authorization_code; details=${formatErrorDetails(error)} What it means
Error "Token exchange request failed. url=${TOKEN_URL}; redirect_uri=${redirectUri}; response_type=authorization_code; details=${formatErrorDetails(error)}" thrown in earendil-works/pi.
Source
Thrown at packages/ai/src/auth/oauth/anthropic.ts:212
redirectUri: string,
signal: AbortSignal,
): Promise<OAuthCredential> {
let responseBody: string;
try {
responseBody = await postJson(
TOKEN_URL,
{
grant_type: "authorization_code",
client_id: CLIENT_ID,
code,
state,
redirect_uri: redirectUri,
code_verifier: verifier,
},
signal,
);
} catch (error) {
throw new Error(
`Token exchange request failed. url=${TOKEN_URL}; redirect_uri=${redirectUri}; response_type=authorization_code; details=${formatErrorDetails(error)}`,
);
}
let tokenData: { access_token: string; refresh_token: string; expires_in: number };
try {
tokenData = JSON.parse(responseBody) as { access_token: string; refresh_token: string; expires_in: number };
} catch (error) {
throw new Error(
`Token exchange returned invalid JSON. url=${TOKEN_URL}; body=${responseBody}; details=${formatErrorDetails(error)}`,
);
}
return {
type: "oauth",
refresh: tokenData.refresh_token,
access: tokenData.access_token,
expires: Date.now() + tokenData.expires_in * 1000 - 5 * 60 * 1000,View on GitHub (pinned to 4af9d21d3b)
Solutions
- Verify the authorization code and redirect_uri, then retry the token exchange.
When it happens
Trigger: Thrown at packages/ai/src/auth/oauth/anthropic.ts:212 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/94f5cbe1d10ebb26.
Report an issue: GitHub.