{"record":{"id":"dfb1d0407aaf5518","repo":"can1357/oh-my-pi","slug":"kimi-device-flow-failed-error-response-statu","errorCode":null,"errorMessage":"Kimi device flow failed: ${error ?? response.status}${description}","messagePattern":"Kimi device flow failed: (.+?)(.+?)","errorType":"exception","errorClass":"AIError.OAuthError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/registry/oauth/kimi.ts","lineNumber":263,"sourceCode":"\t\t\tcontinue;\n\t\t}\n\n\t\tif (error === \"expired_token\") {\n\t\t\tthrow new AIError.OAuthError(\"Kimi device authorization expired\", {\n\t\t\t\tkind: \"validation\",\n\t\t\t\tprovider: \"kimi\",\n\t\t\t});\n\t\t}\n\n\t\tif (error === \"access_denied\") {\n\t\t\tthrow new AIError.OAuthError(\"Kimi device authorization denied\", {\n\t\t\t\tkind: \"validation\",\n\t\t\t\tprovider: \"kimi\",\n\t\t\t});\n\t\t}\n\n\t\tconst description = payload.error_description ? `: ${payload.error_description}` : \"\";\n\t\tthrow new AIError.OAuthError(`Kimi device flow failed: ${error ?? response.status}${description}`, {\n\t\t\tkind: \"polling\",\n\t\t\tprovider: \"kimi\",\n\t\t});\n\t}\n\n\tthrow new AIError.OAuthError(\"Kimi device flow timed out\", {\n\t\tkind: \"timeout\",\n\t\tprovider: \"kimi\",\n\t});\n}\n\n/**\n * Login with Kimi Code OAuth (device code flow).\n */\nexport async function loginKimi(options: OAuthController): Promise<OAuthCredentials> {\n\tconst device = await requestDeviceAuthorization();\n\toptions.onAuth?.({\n\t\turl: device.verificationUriComplete,","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/ai/src/registry/oauth/kimi.ts#L245-L281","documentation":"Generic failure of the Kimi device-authorization token poll. When the poll response carries an error other than the specifically handled authorization_pending/slow_down/access_denied cases (or the HTTP response is not ok), the library throws an OAuthError with kind='polling' embedding the error code or HTTP status plus any error_description from Kimi. It signals an unexpected condition in the device flow other than simple pending, denial, or timeout.","triggerScenarios":"Kimi's token endpoint returns an error code such as 'invalid_grant', 'expired_token', or 'invalid_client' during polling; or the HTTP poll request itself fails with a non-2xx status; error_description from Kimi is appended when present.","commonSituations":"Kimi rotating/disabling the OAuth client credentials (outdated CLI version); device code expiring server-side before user approves; Kimi API outage or rate limiting returning 5xx; network proxy mangling the POST to the token endpoint.","solutions":["Read the embedded status/error code in the message to identify the specific cause","Update the CLI to the latest version so the Kimi client_id and endpoint match current server expectations","Retry loginKimi() after a short wait if the status suggests a transient server error (5xx)","Check Kimi platform status / your network (proxy, VPN) if every attempt fails immediately"],"exampleFix":"// before: hard crash on transient poll failure\nconst auth = await loginKimi();\n// after: retry once on transient failures\nlet auth;\nfor (let attempt = 0; attempt < 2; attempt++) {\n  try { auth = await loginKimi(); break; }\n  catch (e) {\n    if (e instanceof AIError.OAuthError && /: 5\\d\\d/.test(e.message) && attempt === 0) continue;\n    throw e;\n  }\n}","handlingStrategy":"retry","validationCode":"// no pre-call validation possible; ensure CLI is up to date\nconst outdated = !(await isCliVersionCurrent()); // e.g. check latest release\nif (outdated) console.warn('Update the CLI before authenticating with Kimi');","typeGuard":null,"tryCatchPattern":"try {\n  await loginKimi();\n} catch (e) {\n  if (e instanceof AIError.OAuthError && e.kind === 'polling') {\n    const transient = /: 5\\d\\d/.test(e.message);\n    if (transient) await Bun.sleep(2000); // then retry login\n  } else throw e;\n}","preventionTips":["Keep the CLI updated so Kimi client credentials match server expectations","Complete authorization promptly so the device code doesn't expire mid-flow","Avoid proxies/VPNs that interfere with the token endpoint","Distinguish 5xx (retry) from 4xx (re-login / update) using the status embedded in the message"],"tags":["oauth","kimi","device-flow","http-error"],"backgroundTag":"oauth-device-flow-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}