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
- Run the Instagram login command and complete the login in the opened browser window so sessionid is set
- Confirm you actually finished the login (including any 2FA challenge) before the browser closes
- If cookies were cleared, log in again to repopulate the profile's cookie store
- 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
- Run a login/verify step as a precondition for any Instagram command
- Use a persistent browser profile so cookies survive restarts
- Check cookie presence (quickCheck) before every batch run
- After clearing browser data or switching profiles, log in again before running commands
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
- Instagram story publish could not derive current user id fro
- ${result.detail}
- instagram.com
- ${r.detail}
- 12306 tk auth cookie missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/42d5f26f22f573ef.
Report an issue: GitHub.