Introducing the Instagram APIRead more →

Guide · Node.js · Updated

YouTube Transcript in Node.js: A youtube-transcript Alternative

The youtube-transcript npm package works in development and fails in production, where YouTube blocks cloud IP addresses. Here is the same transcript in Node.js, from one request that runs anywhere.

youtube-transcript is the most downloaded transcript package on npm, at close to two hundred thousand downloads a week. It reads the captions YouTube's own player loads, and that is why it breaks on servers: YouTube limits and blocks cloud IP addresses. Its issues are mostly the same report from different hosts: "Blocked in production" on Render, DigitalOcean and Vercel (#43, #54), and empty arrays where a transcript should be (#45). The library's own error says it: "YouTube is receiving too many requests from this IP and now requires solving a captcha to continue".

This guide gets the same transcripts with SocialTap, from any server or serverless function, with the video's details, a channel's videos and their comments.

The code that fails in production

JavaScript
import { fetchTranscript } from "youtube-transcript";

const transcript = await fetchTranscript("dQw4w9WgXcQ");
for (const line of transcript) console.log(line.offset, line.text);

Locally it prints the captions. Deployed, it throws the captcha error or returns nothing, and there's no setting in the package that fixes an IP block.

The same transcript with one API key

SocialTap reads YouTube for you, through its own proxies, and returns the transcript in one schema. Install the SDK (ES modules, Node 20.3 or later):

Install
npm install socialtap

Get a key on the signup page and set it as SOCIALTAP_API_KEY on your server. Every account starts with 100 free credits. Then:

TypeScript SDK
// Save this as app.mjs (an ES module) and run: node app.mjs
import { SocialTap, APIError, NotFoundError, PrivateOrUnavailableError, NoTranscriptError } from "socialtap";

const client = new SocialTap(); // apiKey defaults to process.env.SOCIALTAP_API_KEY

try {
  const res = await client.youtube.transcript.get({ url: "dQw4w9WgXcQ" });
  console.log(res.data);
  console.log(res.credits.charged, res.meta.request_id);
} catch (err) {
  if (err instanceof NotFoundError) {
    // The item does not exist or was deleted.
    console.error(err.code, err.remediation);
  } else if (err instanceof PrivateOrUnavailableError) {
    // The item exists but isn't public: it is private, age- or region-restricted, or needs a login.
    console.error(err.code, err.remediation);
  } else if (err instanceof NoTranscriptError) {
    // The video or audio exists but has no transcript: no captions, and speech-to-text found no speech or didn't run (the media is too long without transcribe_audio=true, or transcribe_audio=false).
    console.error(err.code, err.remediation);
  } else if (err instanceof APIError) {
    // Retryable errors reach you only after the SDK's own retries. Failed requests cost no credits.
    console.error(err.code, err.status, err.retryable, err.remediation, err.requestId);
  } else throw err;
}

Send a watch link, a youtu.be link, a Shorts link or the 11-character ID. The answer has:

  • segments, each with start_ms, end_ms and its text, ready to write as SRT or VTT.
  • text, the whole transcript in one string, for a summary or a search index.
  • is_auto_generated, which says whether you got the creator's captions or YouTube's automatic ones (the creator's win).
  • available_languages, the caption tracks you can ask for with lang.

A video with no captions is transcribed from its audio, at the speech-to-text price: short videos by default, any length with transcribe_audio: true. A video with nothing to transcribe throws NoTranscriptError, which the program above catches.

From youtube-transcript to SocialTap

youtube-transcriptSocialTapEndpoint
fetchTranscript(videoId)client.youtube.transcript.get()YouTube Transcript API
fetchTranscript(videoId, { lang: "de" })lang: "de"YouTube Transcript API

And what the package doesn't read: a video's views, likes, chapters and description with client.youtube.post.get(), a channel's videos with client.youtube.posts.iterate() and their comments with client.youtube.comments.iterate().

The SDK has no dependencies (it uses fetch), so it runs in Vercel and Netlify functions, Cloudflare Workers, Deno and Bun. Keep the key on the server: it's a secret.

What it costs

You pay per successful request:

  • Transcripts from captions: $0.75–$1.97 per 1,000 transcripts. Speech-to-text, for videos without captions, costs more: the YouTube Transcript API page has its price.
  • Videos of a channel: $0.02–$0.04 per 1,000 posts.

Failed requests, including a video with no transcript, cost nothing, and so do cache hits.

Frequently asked questions

Why is youtube-transcript blocked on Vercel or AWS?

YouTube limits and blocks IP addresses that belong to cloud providers, and the package fetches from the IP it runs on. On your laptop the home IP passes, and on a server it gets the captcha error.

Back to contents

Can I call it from the browser?

No. The API key is a secret, so call SocialTap from your server or an API route, and have your front end call that.

Back to contents

Does it return timestamps?

Yes. Each segment has its start and end in milliseconds, where youtube-transcript gives offset and duration.

Back to contents

Do Shorts and live streams work?

Yes. Shorts and live replays have transcripts like any video. A scheduled stream, or one whose recording isn't available, throws NoTranscriptError.

Back to contents

Replace youtube-transcript with one API key.

Get a key, run the code above and see live data in a minute. Failed requests are free.

100free credits
  • No credit card
  • Failed requests are free
  • Works on all 310 endpoints
Start for free Read the docs