{"record":{"id":"34931de5689b0c4d","repo":"musistudio/claude-code-router","slug":"kimi-cli-credential-was-not-found-or-is-expired","errorCode":null,"errorMessage":"Kimi CLI credential was not found or is expired.","messagePattern":"Kimi CLI credential was not found or is expired\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/local-providers/kimi.ts","lineNumber":144,"sourceCode":"    sourceFile: auth?.sourceFile ?? configured.sourceFile,\n    status: \"locked\"\n  };\n}\n\nexport async function importKimiProvider(\n  candidate: LocalAgentProviderCandidate,\n  providerNames: string[]\n): Promise<LocalAgentProviderImportResult> {\n  const configured = readKimiConfiguredProviders().find((item) => item.candidateId === candidate.id);\n  if (!configured) {\n    throw new Error(\"Kimi CLI provider configuration was not found.\");\n  }\n  const usesOauth = Boolean(configured.oauthKey && !configured.apiKey);\n  const oauthReference = kimiOauthReference(configured);\n  const auth = usesOauth ? await resolveKimiAuth(oauthReference) : undefined;\n  const token = configured.apiKey || auth?.accessToken;\n  if (!token || (auth && kimiAccessTokenExpired(auth))) {\n    throw new Error(\"Kimi CLI credential was not found or is expired.\");\n  }\n  const nextCandidate: LocalAgentProviderCandidate = {\n    ...candidate,\n    modelDisplayNames: configured.modelDisplayNames,\n    modelMetadata: configured.modelMetadata,\n    models: configured.models,\n    protocol: configured.protocol\n  };\n  const provider = providerPayload(\n    nextCandidate,\n    uniqueProviderName(providerNames, configured.name),\n    configured.baseUrl,\n    kimiProviderAccountConfig(configured.baseUrl)\n  );\n  const authSuffix = usesOauth ? \"kimi-cli-oauth\" : \"kimi-cli-api-key\";\n  return {\n    candidate: nextCandidate,\n    provider,","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/agents/local-providers/kimi.ts#L126-L162","documentation":"importKimiProvider could not obtain a usable credential: either no API key is configured and OAuth produced no access token, or the OAuth token exists but is considered expired by kimiAccessTokenExpired. Import is aborted so the agent never starts with a dead credential.","triggerScenarios":"configured.apiKey is empty, resolveKimiAuth returned undefined/failed to yield an accessToken, or the resolved auth's expiry check (kimiAccessTokenExpired) is true and refresh did not produce a fresh token.","commonSituations":"User never logged in and set no KIMI_API_KEY; long-lived session where the refresh token also expired; clock skew making a valid token appear expired; credentials file removed.","solutions":["Run kimi login (or set the API key in config) to establish a fresh credential","If OAuth, confirm the stored token set refreshes successfully — if refresh also 401s, re-login is required","Check system clock/NTP sync","Verify the credentials file was not deleted or made unreadable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const auth = await resolveKimiAuth(ref).catch(() => undefined);\nconst hasCredential = Boolean(configured.apiKey || auth?.accessToken);\nconst fresh = !auth || !kimiAccessTokenExpired(auth);\nif (!hasCredential || !fresh) {\n  await kimiLogin(); // refresh before importing\n}","typeGuard":"function hasUsableKimiCredential(cfg: KimiConfig, auth?: KimiTokenSet): boolean {\n  return Boolean(cfg.apiKey || (auth?.accessToken && !kimiAccessTokenExpired(auth)));\n}","tryCatchPattern":"catch (e) {\n  if (e instanceof Error && e.message === 'Kimi CLI credential was not found or is expired.') {\n    await kimiLogin(); // then retry import once\n  }\n}","preventionTips":["Check token expiry before starting agent sessions, not after","Proactively refresh tokens with a safety margin before expiry","Keep an API key configured as a fallback credential"],"tags":["kimi","authentication","expired-token","credentials"],"backgroundTag":"expired-access-token","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}