jackwener/OpenCLI · error · AuthRequiredError

instagram.com

Error message

instagram.com

What it means

handleFetchFailure maps an AUTH_REQUIRED errorCode from the in-page Instagram metadata fetch into an AuthRequiredError for the instagram.com domain. It means Instagram's API rejected the request because the current browser session has no valid (or any) login cookies, so private/authorized data cannot be fetched. The thrown error carries the site 'instagram.com' plus the API's error message.

Source

Thrown at clis/instagram/download.js:314

function ensurePage(page) {
    if (!page)
        throw new CommandExecutionError('Browser session required');
    return page;
}
function normalizeFetchResult(result) {
    const unwrapped = unwrapEvaluateResult(result);
    if (!unwrapped || typeof unwrapped !== 'object' || Array.isArray(unwrapped)) {
        throw new CommandExecutionError('Failed to fetch Instagram media metadata');
    }
    if (typeof unwrapped.ok !== 'boolean') {
        throw new CommandExecutionError('Instagram media metadata returned malformed result');
    }
    return unwrapped;
}
function handleFetchFailure(result) {
    const message = result.error || 'Instagram media fetch failed';
    if (result.errorCode === 'AUTH_REQUIRED') {
        throw new AuthRequiredError('instagram.com', message);
    }
    if (result.errorCode === 'RATE_LIMITED') {
        throw new CliError('RATE_LIMITED', message, 'Wait a few minutes and retry, or switch to a browser session with a warmer Instagram login state.', EXIT_CODES.TEMPFAIL);
    }
    if (result.errorCode === 'PRIVATE_OR_UNAVAILABLE') {
        throw new CommandExecutionError(message, 'Open the post in a logged-in browser session and retry');
    }
    throw new CommandExecutionError(message);
}
async function downloadInstagramMedia(items, outputDir) {
    fs.mkdirSync(outputDir, { recursive: true });
    for (const item of items) {
        const destPath = path.join(outputDir, item.filename);
        const result = await httpDownload(item.url, destPath, {
            timeout: item.type === 'video' ? 120000 : 60000,
        });
        if (!result.success) {
            throw new CommandExecutionError(`Failed to download ${item.filename}: ${result.error || 'unknown error'}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open a browser session and log in to Instagram so session cookies exist, then re-run the command
  2. Re-authenticate if the session expired (log out/in to refresh sessionid and csrftoken)
  3. Verify cookies are being shared with the automation browser profile (correct user-data-dir)
  4. Avoid rapid automated requests that trigger Instagram's session invalidation
Defensive patterns

Strategy: try-catch

Validate before calling

// before running, confirm a logged-in session exists
const loggedIn = await browserPage.evaluate(() => !!document.cookie.match(/sessionid=/));
if (!loggedIn) throw new Error('Log in to Instagram in the browser session first');

Try / catch

try {
  await run(['instagram', 'download', url]);
} catch (e) {
  if (e.name === 'AuthRequiredError' && e.site === 'instagram.com') {
    // open a headed browser session, log in, persist cookies, retry
  } else throw e;
}

Prevention

When it happens

Trigger: The in-page fetch to Instagram's media metadata endpoint returned {ok:false, errorCode:'AUTH_REQUIRED'} — sessionid/csrftoken cookies missing or expired, or Instagram returned 401/403 on the graphql query.

Common situations: Cookie store never populated because the user never logged in to Instagram in the automation browser; expired session after Instagram invalidated old cookies; using a fresh browser profile; Instagram logging the session out for suspicious activity.

Related errors


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