earendil-works/pi · error · Error
OpenAI Codex token response missing fields
Error message
OpenAI Codex token ${operation} response missing fields: ${JSON.stringify(json)} What it means
The Codex token response was HTTP OK but its JSON lacks a usable access_token, refresh_token, or numeric expires_in. Fires when the OAuth server returns a success status with an incomplete payload; the raw JSON is embedded for diagnosis.
Solutions
- Inspect the payload in the message; update parsing if the response shape changed.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/ai/src/auth/oauth/openai-codex.ts:139 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/7448314720120802.
Report an issue: GitHub.
Appendix: source
Thrown at packages/ai/src/auth/oauth/openai-codex.ts:139
}
throw error;
}
}
async function readTokenResponse(response: Response, operation: TokenOperation): Promise<OAuthToken> {
if (!response.ok) {
const text = await response.text().catch(() => "");
throw new Error(`OpenAI Codex token ${operation} failed (${response.status}): ${text || response.statusText}`);
}
const rawJson = await response.json();
const json = rawJson as {
access_token?: string;
refresh_token?: string;
expires_in?: number;
} | null;
if (!json?.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
throw new Error(`OpenAI Codex token ${operation} response missing fields: ${JSON.stringify(json)}`);
}
return {
access: json.access_token,
refresh: json.refresh_token,
expires: Date.now() + json.expires_in * 1000,
};
}
async function exchangeAuthorizationCode(
code: string,
verifier: string,
redirectUri: string,
signal: AbortSignal,
): Promise<OAuthToken> {
const response = await fetchWithLoginCancellation(TOKEN_URL, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },View on GitHub (pinned to 4af9d21d3b)