{"record":{"id":"4fa0daa9e16565cc","repo":"router-for-me/CLIProxyAPI","slug":"xai-device-token-error-s","errorCode":null,"errorMessage":"xai device token error: %s","messagePattern":"xai device token error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/xai/xai.go","lineNumber":315,"sourceCode":"\t}\n\n\tif payload.Error != \"\" {\n\t\tswitch payload.Error {\n\t\tcase \"authorization_pending\":\n\t\t\treturn nil, nil, interval, true\n\t\tcase \"slow_down\":\n\t\t\tnextInterval := interval + defaultPollInterval\n\t\t\treturn nil, nil, nextInterval, true\n\t\tcase \"expired_token\":\n\t\t\treturn nil, fmt.Errorf(\"xai device code expired\"), interval, false\n\t\tcase \"access_denied\":\n\t\t\treturn nil, fmt.Errorf(\"xai device authorization denied\"), interval, false\n\t\tdefault:\n\t\t\tdesc := strings.TrimSpace(payload.ErrorDescription)\n\t\t\tif desc != \"\" {\n\t\t\t\treturn nil, fmt.Errorf(\"xai device token error: %s: %s\", payload.Error, desc), interval, false\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"xai device token error: %s\", payload.Error), interval, false\n\t\t}\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"xai device token request failed with status %d: %s\", resp.StatusCode, strings.TrimSpace(string(body))), interval, false\n\t}\n\tif strings.TrimSpace(payload.AccessToken) == \"\" {\n\t\treturn nil, fmt.Errorf(\"xai device token response missing access_token\"), interval, false\n\t}\n\n\temail, subject := parseJWTIdentity(payload.IDToken)\n\treturn buildTokenData(payload.AccessToken, payload.RefreshToken, payload.IDToken, payload.TokenType, payload.ExpiresIn, email, subject), nil, interval, false\n}\n\n// RefreshTokens refreshes an xAI access token.\nfunc (a *XAIAuth) RefreshTokens(ctx context.Context, refreshToken, tokenEndpoint string) (*TokenData, error) {\n\tif strings.TrimSpace(refreshToken) == \"\" {\n\t\treturn nil, fmt.Errorf(\"xai token refresh: refresh token is required\")","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/xai/xai.go#L297-L333","documentation":"Same catch-all branch as error 292, but the server supplied no error_description, so only the bare error code is reported. This makes diagnosis harder because the raw code (e.g. temporarily_unavailable) is all you get.","triggerScenarios":"Token exchange returns {\"error\":\"some_code\"} with an absent or whitespace-only error_description.","commonSituations":"Server transient failures (temporarily_unavailable) that omit descriptions; stricter API versions dropping descriptive text; proxied responses stripped of detail.","solutions":["Retry after a short backoff for transient codes like temporarily_unavailable","Look the error code up in the current OAuth/xAI error documentation","Log the full response body and status at the call site for correlation with server logs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"device token error:\") {\n    // no description available: retry once for transient codes, then fail with the raw code\n    log.Warnf(\"xAI token error without description: %v\", err)\n    return retryOnceThenFail(err)\n}","preventionTips":["Log the full response body and status at the call site since the error lacks a description","Map known bare codes (temporarily_unavailable, server_error) to retry policies"],"tags":["oauth","xai","auth","api-error"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}