Comparisons

youtube-transcript-api Alternative: When the Library Breaks

Why the youtube-transcript-api Python library gets RequestBlocked on servers, what proxies really cost, and when a hosted transcript API is the better choice.

By FetchTranscript teamPublished Updated 5 min read

youtube-transcript-api is the most popular way to read YouTube captions from Python, and on a laptop it usually just works. The moment the same code runs on AWS, Google Cloud, Azure or most other hosting, YouTube starts refusing the requests and the library raises RequestBlocked or IpBlocked. This article explains why that happens, what the realistic fixes cost, and when a hosted transcript API is the better alternative (and when it is not).

What youtube-transcript-api does well

The library (github.com/jdepoix/youtube-transcript-api) is unofficial, open source under the MIT license, and well maintained. It needs no API key and no headless browser: it calls the same internal endpoints the YouTube web player uses and parses the caption tracks. In version 1.x the API looks like this:

Python
from youtube_transcript_api import YouTubeTranscriptApi

ytt_api = YouTubeTranscriptApi()
transcript = ytt_api.fetch("dQw4w9WgXcQ", languages=["en", "de"])
for snippet in transcript:
    print(snippet.start, snippet.text)

# Which tracks does the video have?
transcript_list = ytt_api.list("dQw4w9WgXcQ")

For a script you run from home, a notebook, or a one-off research project of a few hundred videos, that is hard to beat: it is free and it is fast. If that is your situation, keep using it.

Why it breaks in production

The problem is not the code, it is the network the code runs from. YouTube treats traffic from data-center IP ranges with suspicion, because that is where most automated traffic comes from. Requests from a cloud VM, a serverless function or a container platform are often answered with a bot check or a block instead of the caption data. The library detects this and raises:

  • RequestBlocked: YouTube refused the request, typically because the IP belongs to a cloud provider.
  • IpBlocked: the IP has been blocked after too many requests, which also happens from residential connections if you go fast enough.

The symptoms are confusing at first. Everything passes locally, the first deploy works for a few requests, then failures climb and the same video ID that worked an hour ago now fails. Changing the code does not help, because nothing is wrong with it.

Fix 1: proxies

The library's own answer is proxies. It ships WebshareProxyConfig for rotating residential proxies from Webshare, and GenericProxyConfig for any HTTP or HTTPS proxy:

Python
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.proxies import GenericProxyConfig

ytt_api = YouTubeTranscriptApi(
    proxy_config=GenericProxyConfig(
        http_url="http://user:[email protected]:8080",
        https_url="http://user:[email protected]:8080",
    )
)

This works, but it moves the problem rather than solving it:

  1. Datacenter proxies are not enough. They come from the same kind of IP ranges that are blocked. You need residential (or mobile) proxies, which are billed per gigabyte of traffic.
  2. Bandwidth adds up. A caption request is small, but the pages fetched around it are not, and failed attempts count too. Real-world costs depend heavily on the provider and on how much you retry.
  3. Rotation and retries are on you. Some residential IPs are already flagged; you need retry logic that switches IP, distinguishes "blocked" from "this video has no captions", and backs off.
  4. Maintenance. YouTube changes its internals from time to time. When it does, the library needs an update, and your pipeline is down until you deploy it.

None of this is a reason to avoid proxies, but it is engineering time and a monthly bill that a cost comparison has to include.

Fix 2: yt-dlp

yt-dlp is the other free option. It is a full downloader, so it can also save subtitles without the video:

Shell
yt-dlp --skip-download --write-subs --write-auto-subs --sub-langs en --sub-format vtt \
  "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

It is excellent for command-line work and offline archives, and it supports cookies and proxies. From a server it meets exactly the same IP blocks, though, and it is heavier: each call starts a process and fetches more data than a caption request needs.

Fix 3: a hosted transcript API

A hosted API runs the scraping, the proxy pool, the retries and the caching for you, and you pay per successful call. With FetchTranscript the request is a plain HTTPS call that works the same from your laptop, a Lambda function or a Kubernetes pod, because it never touches YouTube from your IP:

Shell
curl -H "X-API-Key: yt_your_api_key" \
  "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?lang=en&format=json"
Python
import os
import requests

r = requests.get(
    "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ",
    headers={"X-API-Key": os.environ["FETCHTRANSCRIPT_API_KEY"]},
    params={"lang": "en", "format": "json"},
    timeout=60,
)
r.raise_for_status()
data = r.json()
print(data["is_generated"], len(data["segments"]))
JavaScript
// Node 18+ as an ES module (a .mjs file, or "type": "module"), for the top-level await
const res = await fetch(
  "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?lang=en&format=text",
  { headers: { "X-API-Key": process.env.FETCHTRANSCRIPT_API_KEY } }
);
if (!res.ok) throw new Error((await res.json()).detail.error);
const { text } = await res.json();

The full walkthrough, with batches and error handling, is in How to get a YouTube transcript with Python.

Migrating from youtube-transcript-api

The data maps almost one to one, so a migration is usually an afternoon:

youtube-transcript-apiFetchTranscript
ytt_api.fetch(video_id, languages=["en"])GET /v1/transcripts/{video_id}?lang=en
snippet .text, .start, .durationsegment text, start, duration
transcript.is_generatedis_generated
ytt_api.list(video_id)GET /v1/transcripts/{video_id}/languages
TranscriptsDisabled exception404 transcripts_disabled
NoTranscriptFound exception404 no_transcript_found
RequestBlocked, IpBlockednot your problem any more
formatters (SRT, WebVTT, text)format=srt, format=vtt, format=text

Two behaviours differ and are worth knowing. The library's languages argument is a priority list; the API takes one lang, and without it returns the video's original language (manual captions first, then auto-generated, never a translation). If you relied on a fallback list, read the video's tracks with /languages and pick the first of your choices that is there: asking for a language the video has no track in can return YouTube's automatic translation of the original track, much like the library's translate(). And the API also offers format=chunks, segments merged into timestamped chunks for embeddings, which the RAG guide uses.

Cost comparison, honestly

youtube-transcript-api+ residential proxiesHosted API (FetchTranscript)
Pricefreeproxy bill per GB, plus your time100 free calls/month, then $1 per 1,000
Works from cloud serversoften blockedyes, with tuningyes
Failed callsfreestill use bandwidthnot billed
Maintenance when YouTube changesupdate the libraryupdate + proxy tuningnone on your side
Extra datacaptions onlycaptions onlymetadata, chapters, comments, channels, playlists, search

The break-even point depends on volume and on how much your time is worth. At a few thousand transcripts a month, $1 per 1,000 calls is usually cheaper than the engineering hours of keeping a proxy setup healthy. At very large volumes with an in-house scraping team, running your own stack can make sense. Check the numbers on the pricing page: there is no subscription, credits are valid for 12 months and only successful calls are billed.

When the official YouTube API is the answer

It rarely is for transcripts. The YouTube Data API v3 can list caption tracks, but downloading them requires OAuth and only works for videos you own or can edit. We cover the details in Can the YouTube Data API get transcripts?. Before collecting data at scale, whatever tool you choose, read our guide to the legal side of scraping YouTube.

Frequently asked questions

Why does youtube-transcript-api work locally but not on AWS?

YouTube blocks or challenges many requests from cloud providers' IP ranges. Your home connection is a residential IP and is trusted much more, so the same code behaves differently on a server.

Will a VPN or a datacenter proxy fix RequestBlocked?

Usually not for long: most VPN exits and datacenter proxies live in IP ranges YouTube already treats as automated. Residential or mobile proxies are what the library's documentation recommends.

Is the hosted API's data the same as the library's?

Both read YouTube's own caption tracks, so the text and timings are the same. The API adds caching, retries, metadata about the video and other formats such as SRT, WebVTT and chunks.

Can I keep youtube-transcript-api and use the API only as a fallback?

Yes, and it is a reasonable setup: try the library first, and when it raises RequestBlocked or IpBlocked, call the API. You only pay for the videos the library could not fetch.

Does the API need a YouTube account or cookies?

No. You send a FetchTranscript API key in the X-API-Key header; no Google account, cookies or OAuth are involved. Get a key from the sign-up page.

Try it on your own videos

100 free calls every month, no credit card. Then $1 per 1,000 calls, only for the calls that succeed.

← All articles