musistudio/claude-code-router · error · Error

Kimi CLI OAuth token refresh timed out after ${kimiOauthRefr

Error message

Kimi CLI OAuth token refresh timed out after ${kimiOauthRefreshTimeoutMs}ms.

What it means

The Kimi OAuth refresh HTTP request exceeded kimiOauthRefreshTimeoutMs and was aborted via AbortController. The request may be slow or the network hanging.

Source

Thrown at packages/core/src/agents/local-providers/kimi.ts:447

    const refreshToken = readString(payload?.refresh_token) || readString(payload?.refreshToken);
    const expiresIn = numberValue(payload?.expires_in) ?? numberValue(payload?.expiresIn);
    if (!accessToken || !refreshToken || !expiresIn) {
      throw new Error("Kimi CLI OAuth token refresh returned an incomplete token response.");
    }
    const refreshed: KimiTokenSet = {
      ...auth,
      accessToken,
      expiresAt: Math.floor(Date.now() / 1000) + expiresIn,
      expiresIn,
      refreshToken,
      scope: readString(payload?.scope) || auth.scope || "",
      tokenType: readString(payload?.token_type) || readString(payload?.tokenType) || "Bearer"
    };
    persistKimiAuth(refreshed);
    return refreshed;
  } catch (error) {
    if (error instanceof Error && error.name === "AbortError") {
      throw new Error(`Kimi CLI OAuth token refresh timed out after ${kimiOauthRefreshTimeoutMs}ms.`);
    }
    throw error;
  } finally {
    clearTimeout(timer);
  }
}

function persistKimiAuth(auth: KimiTokenSet): void {
  if (!auth.accessToken || !auth.refreshToken) {
    return;
  }
  const payload = {
    access_token: auth.accessToken,
    refresh_token: auth.refreshToken,
    expires_at: auth.expiresAt ?? 0,
    scope: auth.scope ?? "",
    token_type: auth.tokenType ?? "Bearer",
    expires_in: auth.expiresIn ?? 0

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Verify network connectivity to the Kimi auth domain.
  2. Retry — transient slowness often resolves.
  3. Check if a proxy env var (HTTPS_PROXY) points at a dead proxy.
  4. Raise kimiOauthRefreshTimeoutMs if on a legitimately slow link.
Defensive patterns

Strategy: retry

Try / catch

try { await refreshKimiAuth(auth); } catch (e) { if (/timed out/.test(String((e as Error).message))) await sleep(backoff()); else throw e; }

Prevention

When it happens

Trigger: fetch in refreshKimiAuth does not settle before the setTimeout fires, the abort triggers AbortError, which is rethrown as this timeout error.

Common situations: Slow/blocked network, firewall dropping packets silently, DNS hang, or an overloaded auth endpoint.

Understand the failure class

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/c048e14030e25659. Report an issue: GitHub.