jackwener/OpenCLI · error · AuthRequiredError

${result.detail}

Error message

${result.detail}

What it means

An AuthRequiredError raised when the in-page whoami probe reports kind:'auth', meaning Instagram's /users/info endpoint returned 401/403, the ds_user_id cookie was missing, or the response had no user pk (session likely expired). The library surfaces the inner detail (result.detail) as the auth error so the user knows login is required again. It is distinct from generic HTTP failures, which go through error 1935.

Source

Thrown at clis/instagram/auth.js:37

      const r = await fetch('/api/v1/users/' + uid + '/info/', {
        credentials: 'include',
        headers: { 'X-IG-App-ID': '936619743392459', 'Accept': 'application/json' },
      });
      if (r.status === 401 || r.status === 403) {
        return { kind: 'auth', detail: 'Instagram /users/info HTTP ' + r.status };
      }
      if (!r.ok) return { kind: 'http', httpStatus: r.status };
      const d = await r.json();
      const user = d?.user;
      if (!user || !user.pk) {
        return { kind: 'auth', detail: 'Instagram /users/info returned no pk — session likely expired' };
      }
      return { ok: true, user_id: String(user.pk), username: String(user.username || ''), full_name: String(user.full_name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('www.instagram.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from Instagram /users/info`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Instagram whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Instagram probe: ${JSON.stringify(result)}`);
  return { user_id: result.user_id, username: result.username, full_name: result.full_name };
}

registerSiteAuthCommands({
  site: 'instagram',
  domain: 'instagram.com',
  loginUrl: 'https://www.instagram.com/accounts/login/',
  columns: ['user_id', 'username', 'full_name'],
  quickCheck: hasInstagramSessionCookie,
  verify: verifyInstagramIdentity,
  poll: async (page) => {
    if (!await hasInstagramSessionCookie(page)) {
      throw new AuthRequiredError('www.instagram.com', 'Waiting for Instagram sessionid cookie');
    }
    return verifyInstagramIdentity(page);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the Instagram login flow to obtain a fresh session
  2. If Instagram shows a security checkpoint ('suspicious login'), complete it in the browser, then retry
  3. Verify ds_user_id and sessionid cookies are both present for instagram.com after login
  4. Avoid running many automated requests that could trigger Instagram's abuse detection; slow down and retry later

Example fix

// before: stale session
$ opencli instagram whoami
Error: Instagram /users/info HTTP 403

// after: re-authenticate
$ opencli instagram auth login
$ opencli instagram whoami
Defensive patterns

Strategy: try-catch

Validate before calling

// verify the session is fresh before running commands
const cookies = await page.getCookies({ url: 'https://www.instagram.com' });
if (!cookies.some(c => c.name === 'sessionid' && c.value) ||
    !cookies.some(c => c.name === 'ds_user_id' && c.value)) {
  await runInstagramLogin();
}

Type guard

function hasFreshInstagramCookies(cookies) {
  const names = new Set((cookies ?? []).filter(c => c.value).map(c => c.name));
  return names.has('sessionid') && names.has('ds_user_id');
}

Try / catch

try {
  await instagramWhoami();
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await runInstagramLogin();      // session expired or rejected
    return instagramWhoami();
  }
  throw e;
}

Prevention

When it happens

Trigger: page.evaluate whoami probe inside verifyInstagramIdentity returns {kind:'auth', detail}: ds_user_id cookie absent from document.cookie; fetch of /api/v1/users/<uid>/info/ with credentials:'include' responds 401 or 403; or the JSON response lacks user.pk.

Common situations: Session expired between login and command execution; Instagram invalidated the session server-side (password change, security checkpoint); cookies exist but are stale so the API rejects them; ds_user_id cookie blocked by browser cookie settings.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f900ba7e110fa654. Report an issue: GitHub.