jackwener/OpenCLI · error · AuthRequiredError

Instagram sessionid cookie missing

Error message

Instagram sessionid cookie missing

What it means

An AuthRequiredError thrown at the start of verifyInstagramIdentity when the browser page has no non-empty `sessionid` cookie for www.instagram.com. The library requires this cookie as a fast precondition before probing Instagram's whoami API, since every authenticated Instagram API call depends on it. It means you are not logged in (or the cookie jar was lost) and the command cannot proceed.

Source

Thrown at clis/instagram/auth.js:11

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasInstagramSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://www.instagram.com' });
  return cookies.some(c => c.name === 'sessionid' && c.value);
}

async function verifyInstagramIdentity(page) {
  if (!await hasInstagramSessionCookie(page)) {
    throw new AuthRequiredError('www.instagram.com', 'Instagram sessionid cookie missing');
  }
  await page.goto('https://www.instagram.com/');
  await page.wait(2);
  const result = await page.evaluate(`(async () => {
    try {
      const uid = (document.cookie.split('; ').find(c => c.startsWith('ds_user_id=')) || '').split('=')[1] || '';
      if (!uid) return { kind: 'auth', detail: 'Instagram ds_user_id cookie missing' };
      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) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the Instagram login command and complete the login in the opened browser window so sessionid is set
  2. Confirm you actually finished the login (including any 2FA challenge) before the browser closes
  3. If cookies were cleared, log in again to repopulate the profile's cookie store
  4. Check that you are using the same browser profile/user-data-dir the CLI is configured with

Example fix

// before
$ opencli instagram whoami
Error: Instagram sessionid cookie missing

// after
$ opencli instagram auth login
$ opencli instagram whoami
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.instagram.com' });
const hasSession = cookies.some(c => c.name === 'sessionid' && c.value);
if (!hasSession) {
  await runInstagramLogin(); // authenticate before proceeding
}

Type guard

function isLoggedInToInstagram(cookies) {
  return Array.isArray(cookies) &&
    cookies.some(c => c.name === 'sessionid' && typeof c.value === 'string' && c.value !== '');
}

Try / catch

try {
  await instagramCommand();
} catch (e) {
  if (e instanceof AuthRequiredError || /sessionid cookie missing/.test(e.message)) {
    await runInstagramLogin();
    return instagramCommand();
  }
  throw e;
}

Prevention

When it happens

Trigger: Any instagram CLI command that calls verifyInstagramIdentity (login verify, poll, or site-auth flows) when page.getCookies({url:'https://www.instagram.com'}) contains no cookie named 'sessionid' with a non-empty value.

Common situations: Never having run the Instagram login command; the persistent browser profile was cleared or recreated; Instagram expired/invalidated the sessionid so it was dropped; running in a fresh CI/container without the cookie store.

Related errors


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