{"record":{"id":"4f4bd1128b77dc71","repo":"router-for-me/CLIProxyAPI","slug":"kimi-failed-to-create-token-request-w","errorCode":null,"errorMessage":"kimi: failed to create token request: %w","messagePattern":"kimi: failed to create token request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/kimi/kimi.go","lineNumber":275,"sourceCode":"\t\t\tif !shouldContinue {\n\t\t\t\treturn nil, pollErr\n\t\t\t}\n\t\t\t// Continue polling\n\t\t}\n\t}\n}\n\n// exchangeDeviceCode attempts to exchange the device code for an access token.\n// Returns (token, error, shouldContinue).\nfunc (c *DeviceFlowClient) exchangeDeviceCode(ctx context.Context, deviceCode string) (*KimiTokenData, error, bool) {\n\tdata := url.Values{}\n\tdata.Set(\"client_id\", kimiClientID)\n\tdata.Set(\"device_code\", deviceCode)\n\tdata.Set(\"grant_type\", \"urn:ietf:params:oauth:grant-type:device_code\")\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, kimiTokenURL, strings.NewReader(data.Encode()))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"kimi: failed to create token request: %w\", err), false\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: token request failed: %w\", err), false\n\t}\n\tdefer func() {\n\t\tif errClose := resp.Body.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"kimi token exchange: close body error: %v\", errClose)\n\t\t}\n\t}()\n\n\tbodyBytes, err := io.ReadAll(resp.Body)","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/kimi/kimi.go#L257-L293","documentation":"http.NewRequestWithContext failed while building the token-exchange POST to https://auth.kimi.com/api/oauth/token. In practice this only happens for a malformed URL or an invalid method/nil body — all inputs here are hardcoded constants, so a failure is essentially a programming or environment corruption problem, not a network one.","triggerScenarios":"Passing a nil context (NewRequestWithContext panics on nil ctx instead — so realistically only URL parse failure), or the constants kimiTokenURL/method somehow altered. Not reachable in a correctly built binary.","commonSituations":"Custom forks that change kimiTokenURL to an invalid value (typo, missing scheme), unit tests stubbing the constructor incorrectly.","solutions":["If you forked/patched the file, verify kimiTokenURL is a valid absolute URL (https://auth.kimi.com/api/oauth/token)","Otherwise treat as a bug: report it — the stock binary should never hit this path"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only relevant for forks: assert the constant parses\nif _, err := url.Parse(kimiTokenURL); err != nil {\n    return nil, fmt.Errorf(\"bad kimiTokenURL: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not modify URL constants without compile-time checks","Treat occurrence in a stock build as a bug report"],"tags":["kimi","oauth","device-flow","http","unreachable"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}