diegosouzapw/OmniRoute · error

Grok device authorization failed

Error message

Grok device authorization failed

What it means

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.

Solutions

  1. Retry with backoff — xAI device auth rate-limits aggressively
  2. If 'invalid_response', a proxy mangled the JSON — check egress path
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at src/lib/oauth/providers/grok-cli.ts:119 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/1e22532827d44477. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/oauth/providers/grok-cli.ts:119

 * `loopbackPort` shape, so requestDeviceCode/pollToken intentionally ignore
 * whatever config providers.ts passes them and always read GROK_CLI_CONFIG
 * directly.
 */
async function requestDeviceCode(_config?: unknown) {
  const config = GROK_CLI_CONFIG;
  const response = await fetch(config.deviceCodeUrl, {
    method: "POST",
    headers: getGrokBuildOAuthHeaders("ui"),
    body: new URLSearchParams({
      client_id: config.clientId,
      scope: config.scope,
      referrer: GROK_BUILD_OAUTH_REFERRER,
    }),
  });
  const data = await parseOAuthResponse(response);

  if (!response.ok) {
    throw new Error(
      typeof data.error_description === "string"
        ? data.error_description
        : "Grok device authorization failed"
    );
  }
  if (
    typeof data.device_code !== "string" ||
    typeof data.user_code !== "string" ||
    typeof data.verification_uri !== "string"
  ) {
    throw new Error("Grok device authorization response is incomplete");
  }
  if (!/^[A-Za-z0-9-]+$/.test(data.user_code)) {
    throw new Error("Grok returned an invalid device code");
  }
  validateVerificationUri(data.verification_uri);
  if (typeof data.verification_uri_complete === "string") {
    validateVerificationUri(data.verification_uri_complete);

View on GitHub (pinned to a179ffed5b)