jackwener/OpenCLI · error · AuthRequiredError

www.youtube.com

Error message

www.youtube.com

What it means

AuthRequiredError thrown before any API call is made because readYoutubeSapisid found no SAPISID cookie for www.youtube.com. The like command uses SAPISIDHASH authorization, which is only available when the browser profile is logged into YouTube. The library throws it to force re-authentication instead of sending an unauthenticated request that YouTube would reject.

Source

Thrown at clis/youtube/like.js:25

cli({
    site: 'youtube',
    name: 'like',
    access: 'write',
    description: 'Like a YouTube video',
    domain: 'www.youtube.com',
    strategy: Strategy.COOKIE,
    args: [
        { name: 'url', required: true, positional: true, help: 'YouTube video URL or video ID' },
    ],
    columns: ['status', 'message'],
    func: async (page, kwargs) => {
        const videoId = parseVideoId(String(kwargs.url));
        await prepareYoutubeApiPage(page);
        // Read SAPISID directly from the cookie store via CDP — zero document.cookie round-trip
        const sapisid = await readYoutubeSapisid(page);
        if (!sapisid)
            throw new AuthRequiredError('www.youtube.com', 'Not logged in (SAPISID cookie missing)');
        const result = await page.evaluate(`
      (async () => {
        ${SAPISID_HASH_FN}

        const cfg = window.ytcfg?.data_ || {};
        const apiKey = cfg.INNERTUBE_API_KEY;
        const context = cfg.INNERTUBE_CONTEXT;
        if (!apiKey || !context) return { error: 'config', message: 'YouTube config not found' };

        const authHash = await getSapisidHash(${JSON.stringify(sapisid)}, 'https://www.youtube.com');
        if (!authHash) return { error: 'auth', message: 'Not logged in (SAPISID cookie missing)' };

        const resp = await fetch('/youtubei/v1/like/like?key=' + apiKey + '&prettyPrint=false', {
          method: 'POST',
          credentials: 'include',
          headers: {
            'Content-Type': 'application/json',
            'Authorization': authHash,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log into www.youtube.com in the CLI's browser profile, then retry
  2. If already logged in, verify the correct profile directory is being used
  3. Clear Google cookies and log in again to force fresh SAPISID issuance

Example fix

// before
opencli youtube like https://youtu.be/dQw4w9WgXcQ   // AuthRequiredError
// after
opencli auth login youtube   # or open the profile browser, log in, then retry
Defensive patterns

Strategy: validation

Validate before calling

// check the profile can authenticate before calling like
const cookies = await profile.cookies('https://www.youtube.com');
if (!cookies.some(c => c.name === 'SAPISID')) {
  throw new Error('YouTube not logged in: run `opencli auth login youtube` first');
}

Type guard

const hasSapisid = (cookies) => Array.isArray(cookies) && cookies.some(c => c.name === 'SAPISID' && c.domain?.includes('youtube.com'));

Try / catch

try {
  await run('youtube like', [url]);
} catch (e) {
  if (/not logged in|SAPISID/i.test(e.message)) {
    console.error('Auth required: log into youtube.com in the CLI profile, then retry');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `youtube like <url>` while the CLI's browser profile has no logged-in Google/YouTube session (SAPISID cookie absent from the cookie store), or cookies were recently cleared/expired.

Common situations: Freshly provisioned or headless CI profiles with no YouTube login, Google session expired after ~2 weeks, using the wrong profile directory, or a account region/consent flow that never set SAPISID.

Related errors


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