jackwener/OpenCLI · critical · AuthRequiredError

www.youtube.com

Error message

www.youtube.com

What it means

AuthRequiredError re-thrown after the in-page unsubscribe API call reports error === 'auth'. A SAPISID cookie existed, but YouTube's subscribe/unsubscribe internal endpoint responded as unauthenticated (e.g. HTTP 401), so the library surfaces AuthRequiredError for www.youtube.com. This indicates the stored session is no longer server-side valid.

Source

Thrown at clis/youtube/unsubscribe.js:69

            'Content-Type': 'application/json',
            'Authorization': authHash,
            'X-Origin': 'https://www.youtube.com',
          },
          body: JSON.stringify({ context, channelIds: [channelId] }),
        });

        if (resp.status === 401 || resp.status === 403) return { error: 'auth', message: 'Not logged in' };
        if (!resp.ok) {
          const body = await resp.json().catch(() => ({}));
          const errStatus = body?.error?.status || '';
          if (errStatus === 'UNAUTHENTICATED') return { error: 'auth', message: 'Not logged in' };
          return { error: 'http', message: 'HTTP ' + resp.status + (errStatus ? ' ' + errStatus : '') };
        }
        return { ok: true, channelId };
      })()
    `);
        if (result?.error === 'auth') {
            throw new AuthRequiredError('www.youtube.com');
        }
        if (result?.error) {
            throw new CommandExecutionError(result.message || 'Failed to unsubscribe');
        }
        return [{ status: 'success', message: 'Unsubscribed from: ' + (result.channelId || channelInput) }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login to www.youtube.com in the automation profile to mint fresh session cookies, then retry.
  2. Delete stale YouTube cookies and sign in again so SAPISID matches a live session.
  3. Confirm the page-side request sends a correct SAPISIDHASH Authorization header with the current origin and SAPISID.
  4. Update the library/tooling if YouTube altered its internal unsubscribe endpoint auth behavior.
Defensive patterns

Strategy: try-catch

Validate before calling

const sapisid = await readYoutubeSapisid(page);
if (!sapisid) throw new Error('YouTube session invalid — re-login required');

Try / catch

try {
  await unsubscribe({ channel });
} catch (e) {
  if (e.name === 'AuthRequiredError') {
    await refreshYoutubeSession(page);
    return unsubscribe({ channel });
  }
  throw e;
}

Prevention

When it happens

Trigger: The page.evaluate payload returns { error: 'auth' } — the /youtubei/v1/subscription/unsubscribe call returns 401 or another auth-required status despite the SAPISID cookie being present.

Common situations: Expired/stale SAPISID from a revoked Google session; account security changes invalidating cookies; consent or verification walls on the account; YouTube changing auth expectations for internal APIs.

Related errors


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