{"record":{"id":"174862e5bed743b4","repo":"decolua/9router","slug":"no-codex-access-token-available-please-re-authori","errorCode":null,"errorMessage":"No Codex access token available. Please re-authorize the connection.","messagePattern":"No Codex access token available\\. Please re-authorize the connection\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"open-sse/services/usage/codex.js","lineNumber":140,"sourceCode":"    appendCodexQuotaWindows(quotas, \"review\", reviewRateLimit);\n    appendCodexQuotaWindows(quotas, \"spark\", sparkRateLimit);\n\n    return {\n      plan: data.plan_type || data.summary?.plan || \"unknown\",\n      limitReached: getCodexRateLimitBody(normalRateLimit)?.limit_reached || false,\n      reviewLimitReached: getCodexRateLimitBody(reviewRateLimit)?.limit_reached || false,\n      sparkLimitReached: getCodexRateLimitBody(sparkRateLimit)?.limit_reached || false,\n      resetCredits: { availableCount: availableResetCredits },\n      quotas,\n    };\n  } catch (error) {\n    throw new Error(`Failed to fetch Codex usage: ${error.message}`);\n  }\n}\n\nexport async function getCodexRateLimitResetCredits(accessToken, proxyOptions = null, providerSpecificData = null) {\n  if (!accessToken) {\n    throw new Error(\"No Codex access token available. Please re-authorize the connection.\");\n  }\n\n  const accountId = getCodexAccountId(providerSpecificData);\n  const headers = {\n    \"Authorization\": `Bearer ${accessToken}`,\n    \"Accept\": \"application/json\",\n    \"OpenAI-Beta\": \"codex-1\",\n    \"originator\": \"codex_cli_rs\",\n  };\n  if (accountId) headers[\"ChatGPT-Account-ID\"] = accountId;\n\n  const response = await proxyAwareFetch(CODEX_CONFIG.resetCreditsUrl, {\n    method: \"GET\",\n    headers,\n  }, proxyOptions);\n\n  let data = null;\n  try {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/open-sse/services/usage/codex.js#L122-L158","documentation":"getCodexRateLimitResetCredits requires a Codex OAuth access token to call the reset-credits endpoint. When called with an empty/undefined accessToken it throws immediately with this message, instructing the user to re-authorize. It is a guard against calling the API without credentials.","triggerScenarios":"getCodexRateLimitResetCredits is invoked with a null/empty access token — the Codex connection was never authorized, the stored token was cleared, or the token-refresh step failed upstream and null was passed through.","commonSituations":"User never completed Codex (ChatGPT) OAuth; credentials deleted from the dashboard; refresh flow failed leaving no token on the connection.","solutions":["Re-authorize the Codex connection through the dashboard OAuth flow to obtain a new access token","Check that the connection's stored credentials were not wiped (tokenRefresh / oauthCredentialManager state)","Guard the call site: skip the reset-credits fetch when no token exists instead of letting it throw","If the token should exist, check refresh logs for the failure that left it empty"],"exampleFix":"// before\nconst credits = await getCodexRateLimitResetCredits(accessToken);\n// after\nif (!accessToken) {\n  throw new Error(\"Codex connection is not authorized; run the OAuth flow first.\");\n}\nconst credits = await getCodexRateLimitResetCredits(accessToken);","handlingStrategy":"validation","validationCode":"if (typeof accessToken !== 'string' || !accessToken) {\n  // skip the call or trigger the OAuth flow instead of hitting the API\n  return { availableCount: 0, credits: [], notAuthorized: true };\n}","typeGuard":"function hasCodexToken(t) { return typeof t === 'string' && t.length > 0; }","tryCatchPattern":"try {\n  credits = await getCodexRateLimitResetCredits(accessToken, proxyOptions, data);\n} catch (e) {\n  if (e.message.includes('re-authorize')) {\n    return startCodexReauthFlow(); // surface reconnect UI to the user\n  }\n  throw e;\n}","preventionTips":["Check connection authorization state in the dashboard before rendering reset-credit features","Run the Codex OAuth flow at setup and store the token via oauthCredentialManager","Treat this error as 'needs reconnect', not a bug — the message tells the user exactly that","Monitor token refresh job failures so an empty token is caught before API calls"],"tags":["auth","oauth","codex","missing-credential"],"backgroundTag":"missing-access-token","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}