{"record":{"id":"e408b64a6c6a30d0","repo":"decolua/9router","slug":"device-code-request-failed-error-e408b6","errorCode":null,"errorMessage":"`Device code request failed: ${error}`","messagePattern":"`Device code request failed: (.+?)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/oauth/providers/kimi.js","lineNumber":24,"sourceCode":"const kimi = {\n  config: KIMI_CONFIG,\n  flowType: \"device_code\",\n  requestDeviceCode: async (config) => {\n    const { buildKimiHeaders } = await import(\"open-sse/config/appConstants.js\");\n    const deviceId = crypto.randomUUID();\n    const headers = {\n      \"Content-Type\": \"application/x-www-form-urlencoded\",\n      Accept: \"application/json\",\n      ...buildKimiHeaders(deviceId),\n    };\n    const response = await fetch(config.deviceCodeUrl, {\n      method: \"POST\",\n      headers,\n      body: new URLSearchParams({ client_id: config.clientId }),\n    });\n    if (!response.ok) {\n      const error = await response.text();\n      throw new Error(`Device code request failed: ${error}`);\n    }\n    const data = await response.json();\n    const authorizeDeviceUrl = config.authorizeDeviceUrl || \"https://www.kimi.com/code/authorize_device\";\n    return {\n      device_code: data.device_code,\n      user_code: data.user_code,\n      verification_uri: data.verification_uri || authorizeDeviceUrl,\n      verification_uri_complete:\n        data.verification_uri_complete ||\n        `${authorizeDeviceUrl}?user_code=${data.user_code}`,\n      expires_in: data.expires_in,\n      interval: data.interval || 5,\n      _kimiDeviceId: deviceId,\n    };\n  },\n  pollToken: async (config, deviceCode, _codeVerifier, extraData) => {\n    const { buildKimiHeaders } = await import(\"open-sse/config/appConstants.js\");\n    const deviceId = extraData?._kimiDeviceId;","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/providers/kimi.js#L6-L42","documentation":"Thrown by the Kimi OAuth provider when the device-code request — a POST with client_id to the device authorization endpoint — returns a non-2xx response. The upstream error body text is embedded in the message. This is the first step of the device (user_code) login flow, so failure means no device_code/user_code is produced and polling never starts.","triggerScenarios":"The device-code endpoint responds 4xx/5xx: invalid or missing config.clientId, client_id revoked, Kimi service outage, wrong deviceAuthUrl override, or rate limiting.","commonSituations":"Upstream changed the client_id; provider file edited with a bad authorizeDeviceUrl/deviceAuthUrl override; Kimi API temporarily down; corporate firewall blocking www.kimi.com.","solutions":["Inspect the embedded error body in the message for the upstream reason (invalid_client, etc.).","Verify config.clientId matches the currently valid Kimi client id.","Confirm the device authorization endpoint URL is correct and reachable (curl the endpoint).","Retry after a short delay if the body indicates rate limiting or a 5xx outage."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const res = await fetch(deviceAuthUrl, { method: 'HEAD' });\nif (!res.ok && res.status >= 500) throw new Error('Kimi device endpoint unavailable, retry later');","typeGuard":null,"tryCatchPattern":"try {\n  const dc = await kimiProvider.startDeviceFlow(config);\n} catch (e) {\n  if (e.message.startsWith('Device code request failed:')) {\n    const body = e.message.slice('Device code request failed:'.length);\n    // log body; if it indicates rate limit/5xx, retry with backoff, else surface config fix\n  } else throw e;\n}","preventionTips":["Confirm config.clientId is current whenever the Kimi provider is updated.","Add exponential backoff retry for 5xx/rate-limit responses on the device-code endpoint.","Monitor www.kimi.com reachability in health checks before initiating login."],"tags":["oauth","device-code-flow","network","http-4xx"],"backgroundTag":"device-code-flow-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}