can1357/oh-my-pi · error · AIError.OAuthError
Kimi device flow failed: ${error ?? response.status}${descri
Error message
Kimi device flow failed: ${error ?? response.status}${description} What it means
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.
Source
Thrown at packages/ai/src/registry/oauth/kimi.ts:263
continue;
}
if (error === "expired_token") {
throw new AIError.OAuthError("Kimi device authorization expired", {
kind: "validation",
provider: "kimi",
});
}
if (error === "access_denied") {
throw new AIError.OAuthError("Kimi device authorization denied", {
kind: "validation",
provider: "kimi",
});
}
const description = payload.error_description ? `: ${payload.error_description}` : "";
throw new AIError.OAuthError(`Kimi device flow failed: ${error ?? response.status}${description}`, {
kind: "polling",
provider: "kimi",
});
}
throw new AIError.OAuthError("Kimi device flow timed out", {
kind: "timeout",
provider: "kimi",
});
}
/**
* Login with Kimi Code OAuth (device code flow).
*/
export async function loginKimi(options: OAuthController): Promise<OAuthCredentials> {
const device = await requestDeviceAuthorization();
options.onAuth?.({
url: device.verificationUriComplete,View on GitHub (pinned to 9690622007)
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
Example fix
// before: hard crash on transient poll failure
const auth = await loginKimi();
// after: retry once on transient failures
let auth;
for (let attempt = 0; attempt < 2; attempt++) {
try { auth = await loginKimi(); break; }
catch (e) {
if (e instanceof AIError.OAuthError && /: 5\d\d/.test(e.message) && attempt === 0) continue;
throw e;
}
} Defensive patterns
Strategy: retry
Validate before calling
// no pre-call validation possible; ensure CLI is up to date
const outdated = !(await isCliVersionCurrent()); // e.g. check latest release
if (outdated) console.warn('Update the CLI before authenticating with Kimi'); Try / catch
try {
await loginKimi();
} catch (e) {
if (e instanceof AIError.OAuthError && e.kind === 'polling') {
const transient = /: 5\d\d/.test(e.message);
if (transient) await Bun.sleep(2000); // then retry login
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to initiate device authorization: ${initiateResponse.
- Kimi device authorization denied
- Kimi device flow timed out
- Kimi token refresh failed: ${response.status}${description}
- Device authorization initiation failed: ${initResponse.statu
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/dfb1d0407aaf5518.
Report an issue: GitHub.