{"record":{"id":"49e86bb3ae1cad17","repo":"router-for-me/CLIProxyAPI","slug":"kimi-device-code-request-failed-w","errorCode":null,"errorMessage":"kimi: device code request failed: %w","messagePattern":"kimi: device code request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/kimi/kimi.go","lineNumber":197,"sourceCode":"\n// RequestDeviceCode initiates the device flow by requesting a device code from Kimi.\nfunc (c *DeviceFlowClient) RequestDeviceCode(ctx context.Context) (*DeviceCodeResponse, error) {\n\tdata := url.Values{}\n\tdata.Set(\"client_id\", kimiClientID)\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, kimiDeviceCodeURL, strings.NewReader(data.Encode()))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"kimi: failed to create device code request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\tfor k, v := range c.commonHeaders() {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tresp, err := c.httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"kimi: device code request failed: %w\", err)\n\t}\n\tdefer func() {\n\t\tif errClose := resp.Body.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"kimi device code: close body error: %v\", errClose)\n\t\t}\n\t}()\n\n\tbodyBytes, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"kimi: failed to read device code response: %w\", err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"kimi: device code request failed with status %d: %s\", resp.StatusCode, string(bodyBytes))\n\t}\n\n\tvar deviceCode DeviceCodeResponse\n\tif err = json.Unmarshal(bodyBytes, &deviceCode); err != nil {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/kimi/kimi.go#L179-L215","documentation":"The POST to Kimi's device-authorization endpoint failed at the transport level — the request was built but httpClient.Do could not complete DNS, TCP, TLS, or was canceled mid-flight. The device flow cannot even show the user a verification URL until this succeeds. The wrapped error names the underlying transport cause.","triggerScenarios":"No route to auth.kimi.com (blocked in region/firewall); DNS failure for auth.kimi.com; proxy env vars (HTTP(S)_PROXY) pointing to an unreachable proxy; TLS interception rejecting Kimi's certificate; context canceled during the round trip.","commonSituations":"auth.kimi.com unreachable from corporate or regional networks; proxy misconfiguration in the shell launching the process; VPN split-tunnel excluding the auth host; transient provider/network outage.","solutions":["Verify reachability directly: `curl -v https://auth.kimi.com/api/oauth/device_authorization`.","Fix or clear HTTP_PROXY/HTTPS_PROXY/NO_PROXY for the process.","If TLS-intercepted, trust the proxy CA (SSL_CERT_FILE) or bypass the auth host.","Retry after network/DNS is confirmed working; transport blips are self-healing.","If the host is regionally blocked, run login from a network that can reach auth.kimi.com."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight reachability check before starting the device flow\nif _, err := net.DialTimeout(\"tcp\", \"auth.kimi.com:443\", 5*time.Second); err != nil {\n    return fmt.Errorf(\"auth.kimi.com unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"dc, err := c.RequestDeviceCode(ctx)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) {\n        // transport failure: fix network/proxy, then restart device flow\n        log.Warnf(\"kimi device endpoint unreachable: %v\", err)\n    }\n}","preventionTips":["Confirm auth.kimi.com is reachable from the runtime network before login.","Set HTTP(S)_PROXY/NO_PROXY correctly for environments that require a proxy.","Retry the login once after resolving network issues."],"tags":["network","oauth","kimi","proxy","tls","device-flow","dns"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}