jackwener/OpenCLI · error

HTTP ' + res.status + ' - make sure you are logged in to Ins

Error message

HTTP ' + res.status + ' - make sure you are logged in to Instagram

What it means

This error is thrown in clis/instagram/saved.js when the fetch to Instagram's collection-posts API (or saved-posts endpoint) returns a non-OK HTTP status. The CLI uses session credentials, so a failed status almost always means the stored cookie/session is invalid or expired and Instagram rejected the request as unauthenticated.

Source

Thrown at clis/instagram/saved.js:37

  const opts = { credentials: 'include', headers };

  let endpoint = 'https://www.instagram.com/api/v1/feed/saved/posts/';
  if (collectionArg && String(collectionArg).trim()) {
    const wanted = String(collectionArg).trim().toLowerCase();
    const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%2C%22ALL_MEDIA_AUTO_COLLECTION%22%5D', opts);
    if (!listRes.ok) throw new Error('Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram');
    const listData = await listRes.json();
    const collections = listData?.items || [];
    const match = collections.find((c) => String(c?.collection_name || '').trim().toLowerCase() === wanted);
    if (!match) {
      const names = collections.map((c) => c?.collection_name).filter(Boolean);
      throw new Error('Collection not found: ' + collectionArg + '. Available: ' + (names.length ? names.join(', ') : '(none)'));
    }
    endpoint = 'https://www.instagram.com/api/v1/feed/collection/' + encodeURIComponent(match.collection_id) + '/posts/';
  }

  const res = await fetch(endpoint, opts);
  if (!res.ok) throw new Error('HTTP ' + res.status + ' - make sure you are logged in to Instagram');
  const data = await res.json();
  return (data?.items || []).slice(0, limit).map((item, i) => {
    const m = item?.media;
    return {
      index: i + 1,
      user: m?.user?.username || '',
      caption: (m?.caption?.text || '').replace(/\\n/g, ' ').substring(0, 100),
      likes: m?.like_count ?? 0,
      comments: m?.comment_count ?? 0,
      type: m?.media_type === 1 ? 'photo' : m?.media_type === 2 ? 'video' : 'carousel',
    };
  });
})()
` },
    ],
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-authenticate: log in to Instagram and refresh the session cookie/credentials used by the CLI
  2. Print res.status before throwing to confirm whether it is 401 (login) or 429 (rate limit)
  3. If 429, wait and retry later; reduce request frequency
  4. Verify the collection exists by checking the names listed in the 'Collection not found' error

Example fix

// before
const res = await fetch(endpoint, opts);
if (!res.ok) throw new Error('HTTP ' + res.status + ' - make sure you are logged in to Instagram');
// after
const res = await fetch(endpoint, opts);
if (!res.ok) {
  if (res.status === 429) throw new Error('Rate limited by Instagram (HTTP 429); retry later');
  throw new Error('HTTP ' + res.status + ' - session invalid, re-run `instagram login`');
}
Defensive patterns

Strategy: try-catch

Validate before calling

const cookie = opts.headers?.Cookie || '';
if (!cookie.includes('sessionid')) throw new Error('No Instagram session cookie; run login first');

Type guard

function isOk(res) { return typeof res === 'object' && res !== null && typeof res.status === 'number' && res.status >= 200 && res.status < 300; }

Try / catch

try {
  const saved = await getSaved({ limit: 10 });
} catch (e) {
  if (/HTTP 40[13]/.test(e.message)) { await login(); /* retry once */ }
  else if (/HTTP 429/.test(e.message)) { await sleep(60000); }
  else throw e;
}

Prevention

When it happens

Trigger: res.ok is false on `await fetch(endpoint, opts)` where endpoint is the saved-posts URL or 'https://www.instagram.com/api/v1/feed/collection/<id>/posts/'. Any 401/403/429 response triggers it.

Common situations: Expired or missing Instagram session cookie, running without being logged in, Instagram rate-limiting or blocking the request, or an invalid collection_id producing a 404.

Related errors


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