{"record":{"id":"77390f2f3e1a94df","repo":"router-for-me/CLIProxyAPI","slug":"xai-device-code-create-request-w","errorCode":null,"errorMessage":"xai device code: create request: %w","messagePattern":"xai device code: create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/xai/xai.go","lineNumber":138,"sourceCode":"}\n\n// RequestDeviceCode requests a device authorization code from the given endpoint.\nfunc (a *XAIAuth) RequestDeviceCode(ctx context.Context, deviceAuthorizationEndpoint, tokenEndpoint string) (*DeviceCodeResponse, error) {\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\tdeviceAuthorizationEndpoint = strings.TrimSpace(deviceAuthorizationEndpoint)\n\tif deviceAuthorizationEndpoint == \"\" {\n\t\treturn nil, fmt.Errorf(\"xai device code: device authorization endpoint is required\")\n\t}\n\n\tform := url.Values{\n\t\t\"client_id\": {ClientID},\n\t\t\"scope\":     {Scope},\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, deviceAuthorizationEndpoint, strings.NewReader(form.Encode()))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"xai device code: create request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\n\tresp, err := a.httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"xai 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(\"xai device code: close response body error: %v\", errClose)\n\t\t}\n\t}()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"xai device code: read response: %w\", err)\n\t}","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/xai/xai.go#L120-L156","documentation":"Error \"xai device code: create request: %w\" thrown in router-for-me/CLIProxyAPI.","triggerScenarios":"Thrown at internal/auth/xai/xai.go:138 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the device authorization endpoint URL is valid.","Check the wrapped error for request construction details."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}