jackwener/OpenCLI · error · CommandExecutionError

Instagram private route could not derive X-IG-App-ID from…

Error message

Instagram private route could not derive X-IG-App-ID from instagram runtime

What it means

The private API route must send the X-IG-App-ID header. It is taken from the instagram runtime appId or the captured browser context; when neither provides it the request would be rejected by Instagram, so this error is thrown up front.

Solutions

  1. Set appId in the instagram runtime config (the standard web app id: 936619743392459)
  2. Ensure a page load happens before the private call so headers are captured
  3. Re-login / reload instagram.com to refresh captured context
  4. Upgrade the CLI if Instagram rotated app ids and captures no longer include it

Example fix

// before
runtime = { csrfToken };
// after
runtime = { csrfToken, appId: '936619743392459', instagramAjax: ajaxValue };
Defensive patterns

Strategy: validation

Validate before calling

if (!runtime.appId && !captured.igAppId) {
  runtime.appId = '936619743392459'; // standard Instagram web app id
}

Type guard

function hasIgAppId(rt) {
  return typeof rt?.appId === 'string' && /^\d{10,}$/.test(rt.appId);
}

Try / catch

try {
  await publishPrivate(cfg);
} catch (e) {
  if (/could not derive X-IG-App-ID/.test(e.message)) {
    cfg.runtime.appId = '936619743392459'; // retry with known app id
  } else throw e;
}

Prevention

When it happens

Trigger: resolveInstagramPrivatePublishConfig runs with runtime.appId unset and no captured context containing igAppId.

Common situations: Minimal runtime config without appId, private route invoked before any page load captured headers, Instagram changed the app id and captures are stale/absent.

Related errors


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

Appendix: source

Thrown at clis/instagram/_shared/private-publish.js:113

            await page.wait({ time: 2 });
            const [cookies, runtime, entries] = await Promise.all([
                page.getCookies({ domain: 'instagram.com' }),
                page.evaluate(buildReadInstagramRuntimeInfoJs()),
                typeof page.readNetworkCapture === 'function'
                    ? page.readNetworkCapture()
                    : Promise.resolve([]),
            ]);
            const captureEntries = (Array.isArray(entries) ? entries : []);
            const capturedContext = derivePrivateApiContextFromCapture(captureEntries)
                ?? derivePartialPrivateApiContextFromCapture(captureEntries);
            const csrfToken = runtime?.csrfToken || getCookieValue(cookies, 'csrftoken') || capturedContext.csrfToken || '';
            const igAppId = runtime?.appId || capturedContext.igAppId || '';
            const instagramAjax = runtime?.instagramAjax || capturedContext.instagramAjax || '';
            if (!csrfToken) {
                throw new CommandExecutionError('Instagram private route could not derive CSRF token from browser session');
            }
            if (!igAppId) {
                throw new CommandExecutionError('Instagram private route could not derive X-IG-App-ID from instagram runtime');
            }
            if (!instagramAjax) {
                throw new CommandExecutionError('Instagram private route could not derive X-Instagram-AJAX from instagram runtime');
            }
            const asbdId = capturedContext.asbdId || '';
            const igWwwClaim = capturedContext.igWwwClaim || '';
            const webSessionId = capturedContext.webSessionId || '';
            return {
                apiContext: {
                    asbdId,
                    csrfToken,
                    igAppId,
                    igWwwClaim,
                    instagramAjax,
                    webSessionId,
                },
                jazoest: deriveInstagramJazoest(csrfToken),
            };

View on GitHub (pinned to 49907e53dc)