can1357/oh-my-pi · error · AIError.OAuthError

Device authorization initiation failed: ${initResponse.statu

Error message

Device authorization initiation failed: ${initResponse.status}

What it means

Thrown by loginOpenAICodexDevice when the initial device-authorization request (POST to the device auth endpoint with the client_id) returns a non-ok HTTP status. Classified kind='device-auth' with the status attached, it means the device flow could not even be started — no user_code or verification URL was issued.

Source

Thrown at packages/ai/src/registry/oauth/openai-codex.ts:259

/**
 * Login with OpenAI Codex using the device-code (headless) flow.
 *
 * Avoids a local callback server entirely — useful when port 1455 is unavailable
 * or when the browser callback flow fails with 403 (e.g. network/proxy issues).
 */
export async function loginOpenAICodexDevice(ctrl: OAuthController): Promise<OAuthCredentials> {
	ctrl.onProgress?.("Initiating device authorization…");

	const initResponse = await fetch(DEVICE_USERCODE_URL, {
		method: "POST",
		headers: { "Content-Type": "application/json" },
		body: JSON.stringify({ client_id: CLIENT_ID }),
		signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS),
	});

	if (!initResponse.ok) {
		throw new AIError.OAuthError(`Device authorization initiation failed: ${initResponse.status}`, {
			kind: "device-auth",
			status: initResponse.status,
		});
	}

	const initData = (await initResponse.json()) as {
		device_auth_id?: string;
		user_code?: string;
		interval?: string | number;
	};

	if (!initData.device_auth_id || !initData.user_code) {
		throw new AIError.OAuthError("Device authorization response missing required fields", { kind: "validation" });
	}

	const userCode = initData.user_code;
	const pollIntervalMs =
		(typeof initData.interval === "number"

View on GitHub (pinned to 9690622007)

Solutions

  1. Check the embedded HTTP status: 401/403 points to client_id problems (update the CLI); 429 means wait and retry; 5xx means OpenAI-side trouble
  2. Update the CLI to the latest release
  3. Verify network access to the OpenAI auth endpoint from this machine (curl the URL, check proxy settings)
  4. Wait a few minutes and retry if rate-limited

Example fix

// before: bare call crashes on transient failure
const auth = await loginOpenAICodexDevice();
// after: retry 5xx once
let auth;
try { auth = await loginOpenAICodexDevice(); }
catch (e) {
  if (e instanceof AIError.OAuthError && /: 5\d\d$/.test(e.message)) auth = await loginOpenAICodexDevice();
  else throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

// pre-flight network check before starting the device flow
const probe = await fetch('https://auth.openai.com/.well-known/openid-configuration', { signal: AbortSignal.timeout(5000) }).catch(() => null);
if (!probe || !probe.ok) throw new Error('OpenAI auth endpoint unreachable — check network/proxy before login');

Try / catch

try {
  const auth = await loginOpenAICodexDevice();
} catch (e) {
  if (e instanceof AIError.OAuthError && e.kind === 'device-auth') {
    if ((e.status ?? 0) >= 500 || e.status === 429) {
      await Bun.sleep(5000); // retry after backoff
    } else {
      // 401/403: update CLI (client_id rejected)
    }
  } else throw e;
}

Prevention

When it happens

Trigger: OpenAI rejects the client_id (CLI version predates a client rotation); 4xx for malformed request or blocked client; 429 rate limiting after many login attempts; 5xx from an OpenAI outage; a proxy/agent blocking the POST. Runs with a TOKEN_REQUEST_TIMEOUT_MS abort signal, though timeouts surface as abort errors rather than this message.

Common situations: Outdated CLI after OpenAI rotated OAuth clients; corporate firewall/proxy intercepting auth.openai.com; hammering login repeatedly and tripping rate limits; OpenAI incident making the device endpoint unavailable.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/18005b1c05d62dff. Report an issue: GitHub.