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

  1. Read the embedded status/error code in the message to identify the specific cause
  2. Update the CLI to the latest version so the Kimi client_id and endpoint match current server expectations
  3. Retry loginKimi() after a short wait if the status suggests a transient server error (5xx)
  4. 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

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


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/dfb1d0407aaf5518. Report an issue: GitHub.