{"record":{"id":"b7490bb472596102","repo":"jackwener/OpenCLI","slug":"http-result-httpstatus-from-api-user","errorCode":null,"errorMessage":"HTTP ${result.httpStatus} from /api/user","messagePattern":"HTTP (.+?) from /api/user","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/kimi/auth.js","lineNumber":38,"sourceCode":"  const result = await page.evaluate(`(async () => {\n    try {\n      const token = ${JSON.stringify(token)};\n      const res = await fetch('/api/user', { credentials: 'include', headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Kimi /api/user HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (!d || !d.id) {\n        return { kind: 'auth', detail: 'Kimi /api/user returned no id — anonymous' };\n      }\n      return { ok: true, user_id: String(d.id), name: String(d.name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('kimi.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/user`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Kimi whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Kimi probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'kimi',\n  domain: 'kimi.com',\n  loginUrl: 'https://www.kimi.com/',\n  columns: ['user_id', 'name'],\n  quickCheck: hasKimiSessionCookie,\n  verify: verifyKimiIdentity,\n  poll: async (page) => {\n    if (!await hasKimiSessionCookie(page)) {\n      throw new AuthRequiredError('kimi.com', 'Waiting for Kimi auth cookies');\n    }\n    return verifyKimiIdentity(page);\n  },","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/kimi/auth.js#L20-L56","documentation":"The in-page probe of Kimi's `/api/user` returns `{kind:'http', httpStatus}` when the fetch completes but with a non-success, non-auth HTTP status. verifyKimiIdentity surfaces that as CommandExecutionError with the status code. This signals a server-side or request-level problem rather than a plain login problem.","triggerScenarios":"`/api/user` responds with an unexpected HTTP status (e.g. 429 rate limit, 500 server error, 403 from a WAF/bot protection) that the probe classifies as 'http' rather than 'auth'.","commonSituations":"Hammering Kimi's API in a loop and hitting rate limiting; Kimi outage or maintenance returning 5xx; Cloudflare/bot-protection challenging automated requests; regional blocking of the API endpoint.","solutions":["Check the reported HTTP status: retry after a delay for 429/5xx, since these are usually transient","Reduce request frequency / add backoff between Kimi commands","Load https://www.kimi.com in the browser to pass any bot-protection challenge, then retry","If persistent, check Kimi status/changes to /api/user and update the probe"],"exampleFix":"// before\nawait page.evaluate(fetchProbe); // throws HTTP 429\n// after\nawait page.wait(30); // back off before retrying\nconst result = await page.evaluate(fetchProbe);","handlingStrategy":"retry","validationCode":"const res = await page.evaluate(`fetch('/api/user').then(r => r.status).catch(() => -1)`);\nif (res === 429 || res >= 500) {\n  await new Promise(r => setTimeout(r, 30000)); // back off before retry\n}","typeGuard":"function isTransientHttp(status) {\n  return status === 429 || (status >= 500 && status <= 599);\n}","tryCatchPattern":"try {\n  await kimiWhoami();\n} catch (e) {\n  const m = e.message.match(/HTTP (\\d+) from \\/api\\/user/);\n  if (m && (m[1] === '429' || +m[1] >= 500)) {\n    await sleep(30000);\n    return kimiWhoami();\n  }\n  throw e;\n}","preventionTips":["Add exponential backoff between Kimi API calls","Keep a browser tab open on kimi.com to satisfy bot-protection checks","Monitor for 5xx bursts and pause automation during Kimi incidents"],"tags":["kimi","http-error","api","rate-limit"],"backgroundTag":"http-5xx-api-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}