DEV Community

Mohammed Usama
Mohammed Usama

Posted on

Fixing RequestBlocked in youtube-transcript-api on a cloud server

A YouTube transcript script usually starts small. You install youtube-transcript-api, pass it a video id, and the transcript prints. Then you move the same code to a server so it can run every night, and the calls start failing with RequestBlocked or IpBlocked.

The library's README gives the reason: "YouTube has started blocking most IPs that are known to belong to cloud providers." It names AWS, Google Cloud and Azure, which covers a lot of the places a nightly job runs.

You can keep the library and add a proxy, or you can hand the fetching to a hosted actor that returns JSON.

Fix 1: keep the library and add a residential proxy

The library has proxy support built in, and its README recommends rotating residential proxies over static ones. With a Webshare account it looks like this:

from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.proxies import WebshareProxyConfig
ytt_api = YouTubeTranscriptApi(
    proxy_config=WebshareProxyConfig(
        proxy_username="<proxy-username>",
        proxy_password="<proxy-password>",
    )
)
transcript = ytt_api.fetch("jNQXAC9IVRw")
Enter fullscreen mode Exit fullscreen mode

Other providers plug in through GenericProxyConfig(http_url=..., https_url=...). This fix makes sense if you already pay for proxies and you fetch one video at a time. You still write the code that turns a channel or a playlist into video ids, and the proxy plan is one more bill to watch.

Fix 2: call a hosted actor and get JSON back

I build data tools on Apify under the name Talcoe, and one of them fetches YouTube transcripts. You give it video links, channels, @handles or playlists in one list. It returns one record per video with the transcript as plain text, timestamped segments, SRT or VTT. It runs on Apify's residential proxy by default, so there is no proxy account to manage.

This is the request I sent while writing this post:

curl -X POST "https://api.apify.com/v2/acts/talcoe~youtube-transcripts/run-sync-get-dataset-items" \
  -H "Authorization: Bearer YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"sources": ["@Fireship", "jNQXAC9IVRw"], "maxVideosPerSource": 2, "formats": ["text", "srt"]}'
Enter fullscreen mode Exit fullscreen mode

Three records came back after 34 seconds. Two were the newest Fireship videos at the time, with auto generated captions of 1,205 and 939 words. The third was "Me at the zoo," the first video uploaded to YouTube, which starts like this in SRT:

1
00:00:01,200 --> 00:00:03,360
All right, so here we are, in front of the elephants
Enter fullscreen mode Exit fullscreen mode

Each record also has the title, channel, publish date, duration, view count, caption language and an autoGenerated flag.

Here is the same call from Python, set up for a nightly job that only wants new videos:

import requests
resp = requests.post(
    "https://api.apify.com/v2/acts/talcoe~youtube-transcripts/run-sync-get-dataset-items",
    headers={"Authorization": f"Bearer {APIFY_TOKEN}"},
    json={
        "sources": ["@Fireship"],
        "maxVideosPerSource": 5,
        "publishedAfter": "2026-11-01",
        "formats": ["text", "segments"],
        "language": "en",
    },
    timeout=300,
)
for video in resp.json():
    print(video["title"], video["wordCount"], len(video["segments"]))
Enter fullscreen mode Exit fullscreen mode

That run returned five November videos, each between 939 and 1,311 words long.

Some details matter once this runs on a schedule:

  • A video with no captions costs nothing and goes to a NO_TRANSCRIPT record. Turn fallbackToAnyLanguage off and the same happens to a video that lacks your language, with the languages it does have listed.
  • publishedAfter keeps only channel and playlist videos from that date on.
  • maxResults stops the run at a set number of transcripts, which also caps the bill.
  • When YouTube shows a bot check on a video, the actor does not try to get past it. That video goes to an ERRORS record and costs nothing.

The price is half a cent per transcript plus a half cent start fee per run, and higher Apify plans pay less per transcript.

From an AI agent

The actor also works as an MCP tool. To add it to Claude Code, run this with your token in place of YOUR_APIFY_TOKEN.

claude mcp add --transport http youtube-transcripts "https://mcp.apify.com/?tools=talcoe/youtube-transcripts" --header "Authorization: Bearer YOUR_APIFY_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Then ask for something like "Get the transcripts of the 10 newest videos on @Fireship and list the products each one mentions." Cursor and VS Code accept the same URL and header.

Which fix to use

Keep the library and add the proxy if you fetch single videos and already have a proxy account. Use the hosted call if you want whole channels or playlists, subtitle files, or a nightly job with less code to maintain.

The actor's page is apify.com/talcoe/youtube-transcripts. If you need a field it does not return, open an issue there and I will look at it.

Written with help from an AI assistant. The curl and Python examples above ran against the live actor before this post went up.

Top comments (0)