{"record":{"id":"1e22532827d44477","repo":"diegosouzapw/OmniRoute","slug":"grok-device-authorization-failed","errorCode":null,"errorMessage":"Grok device authorization failed","messagePattern":"Grok device authorization failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/oauth/providers/grok-cli.ts","lineNumber":119,"sourceCode":" * `loopbackPort` shape, so requestDeviceCode/pollToken intentionally ignore\n * whatever config providers.ts passes them and always read GROK_CLI_CONFIG\n * directly.\n */\nasync function requestDeviceCode(_config?: unknown) {\n  const config = GROK_CLI_CONFIG;\n  const response = await fetch(config.deviceCodeUrl, {\n    method: \"POST\",\n    headers: getGrokBuildOAuthHeaders(\"ui\"),\n    body: new URLSearchParams({\n      client_id: config.clientId,\n      scope: config.scope,\n      referrer: GROK_BUILD_OAUTH_REFERRER,\n    }),\n  });\n  const data = await parseOAuthResponse(response);\n\n  if (!response.ok) {\n    throw new Error(\n      typeof data.error_description === \"string\"\n        ? data.error_description\n        : \"Grok device authorization failed\"\n    );\n  }\n  if (\n    typeof data.device_code !== \"string\" ||\n    typeof data.user_code !== \"string\" ||\n    typeof data.verification_uri !== \"string\"\n  ) {\n    throw new Error(\"Grok device authorization response is incomplete\");\n  }\n  if (!/^[A-Za-z0-9-]+$/.test(data.user_code)) {\n    throw new Error(\"Grok returned an invalid device code\");\n  }\n  validateVerificationUri(data.verification_uri);\n  if (typeof data.verification_uri_complete === \"string\") {\n    validateVerificationUri(data.verification_uri_complete);","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/oauth/providers/grok-cli.ts#L101-L137","documentation":"requestDeviceCode's POST to the Grok device-authorization endpoint returned a non-OK status after parseOAuthResponse consumed the body. Means Grok refused to issue a device code (bad client_id, disallowed scope/referrer, or upstream outage), aborting the CLI login flow before polling starts.","triggerScenarios":"Thrown at src/lib/oauth/providers/grok-cli.ts:119 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry with backoff — xAI device auth rate-limits aggressively","If 'invalid_response', a proxy mangled the JSON — check egress path"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}