Mintplex-Labs/anything-llm · error · YoutubeTranscriptError

Impossible to retrieve Youtube video ID.

Error message

Impossible to retrieve Youtube video ID.

What it means

Thrown by the static `YoutubeTranscript.retrieveVideoId(videoId)` when the input is neither an 11-character string nor parseable by `validYoutubeVideoUrl`. This is the entry-point guard for the transcript fetcher and mirrors error 41, but it also accepts a bare 11-char id as a fast path, so it fires only when both the length check and URL extraction fail.

Source

Thrown at collector/utils/extensions/YoutubeTranscript/YoutubeLoader/youtube-transcript.js:237

      }

      const responseData = await response.json();
      return this.#extractTranscriptFromResponse(responseData);
    } catch (e) {
      throw new YoutubeTranscriptError(e.message || e);
    }
  }

  /**
   * Extract video ID from a YouTube URL or verify an existing ID
   * @param {string} videoId - Video URL or ID
   * @returns {string} YouTube video ID
   */
  static retrieveVideoId(videoId) {
    if (videoId.length === 11) return videoId; // already a valid ID most likely
    const matchedId = validYoutubeVideoUrl(videoId, true);
    if (matchedId) return matchedId;
    throw new YoutubeTranscriptError(
      "Impossible to retrieve Youtube video ID."
    );
  }
}

module.exports = {
  YoutubeTranscript,
  YoutubeTranscriptError,
};

View on GitHub (pinned to 526360e320)

Solutions

  1. Trim the input and, if it looks like an 11-char id, pass it directly to bypass URL parsing.
  2. Run `validYoutubeVideoUrl(input, true)` first and reject with a UI-friendly message if it returns null.
  3. For URLs, prefer extracting the id with `YoutubeLoader.getVideoID(url)` and passing the bare id.
  4. Guard against playlist/channel URLs upstream and ask the user for a single video URL.

Example fix

// before
const transcript = await YoutubeTranscript.fetchTranscript(rawInput);

// after
const id = YoutubeTranscript.retrieveVideoId(String(rawInput).trim());
if (!id) throw new Error('Please provide a YouTube video URL or 11-character id');
const transcript = await YoutubeTranscript.fetchTranscript(id);
Defensive patterns

Strategy: validation

Validate before calling

function resolveVideoId(input) {
  const v = String(input || '').trim();
  if (/^[A-Za-z0-9_-]{11}$/.test(v)) return v;
  const id = validYoutubeVideoUrl(v, true);
  if (id) return id;
  throw new Error('Provide a YouTube video URL or an 11-character id');
}

Type guard

function isYoutubeIdOrUrl(v) {
  const s = String(v || '').trim();
  return /^[A-Za-z0-9_-]{11}$/.test(s) || !!validYoutubeVideoUrl(s, true);
}

Try / catch

try {
  const id = YoutubeTranscript.retrieveVideoId(input);
} catch (e) {
  if (/Impossible to retrieve Youtube video ID/i.test(e.message)) {
    return { error: 'Please provide a valid YouTube video URL or id.' };
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing an id shorter/longer than 11 chars that is also not a URL (`'abc'`, `'123456789012'`); passing a non-YouTube URL; passing a YouTube URL whose id segment failed extraction; undefined/null after the `.length` access already threw elsewhere; a playlist URL with no video id.

Common situations: Frontend passes the raw YouTube page URL or a `youtu.be` short link in a format the validator rejects; user submits a playlist or channel link instead of a video; whitespace or a trailing slash in the id makes the length !== 11.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/258443a76fbac634. Report an issue: GitHub.