earendil-works/pi · error · Error

Kimi Code token refresh unauthorized (status ${response.stat

Error message

Kimi Code token refresh unauthorized (status ${response.status})${description}

What it means

Error "Kimi Code token refresh unauthorized (status ${response.status})${description}" thrown in earendil-works/pi.

Source

Thrown at packages/ai/src/auth/oauth/kimi-coding.ts:252

					grant_type: "refresh_token",
					refresh_token: refreshTokenValue,
				}),
				signal: requestSignal(signal),
			});
		} catch (error) {
			lastError = error instanceof Error ? error : new Error(String(error));
			continue;
		}

		const json = await readJson(response);
		if (response.ok) {
			return parseTokenResponse(json, "refresh");
		}

		// Unauthorized: the stored credential is dead; Models clears it and prompts re-login.
		if (response.status === 401 || response.status === 403 || json?.error === "invalid_grant") {
			const description = typeof json?.error_description === "string" ? `: ${json.error_description}` : "";
			throw new Error(`Kimi Code token refresh unauthorized (status ${response.status})${description}`);
		}

		if (isRetryableRefreshFailure(response) && attempt < REFRESH_MAX_RETRIES) {
			lastError = new Error(`Kimi Code token refresh failed with status ${response.status}`);
			continue;
		}

		const text = JSON.stringify(json);
		throw new Error(`Kimi Code token refresh failed with status ${response.status}${text ? `: ${text}` : ""}`);
	}

	throw lastError ?? new Error("Kimi Code token refresh failed");
}

async function loginKimiCoding(interaction: ProviderAuthInteraction): Promise<OAuthCredential> {
	const oauthHost = getOauthHost();
	const device = await startDeviceAuthorization(oauthHost, interaction.signal);
	interaction.notify({

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Re-login; the refresh token is invalid or expired.

When it happens

Trigger: Thrown at packages/ai/src/auth/oauth/kimi-coding.ts:252 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/01dd9710b7009168. Report an issue: GitHub.