LangChain YoutubeLoader fails on a server: why, and a loader that works

Checked on 2026-11-18.

LangChain's YoutubeLoader turns a video into documents in two lines. It runs fine in a notebook on your laptop. Deployed to a server, the same two lines start raising errors. The loader did not change: the address your request comes from did.

Why it fails

Python
# pip install langchain-community youtube-transcript-api
from langchain_community.document_loaders import YoutubeLoader

loader = YoutubeLoader.from_youtube_url("https://www.youtube.com/watch?v=jNQXAC9IVRw")
docs = loader.load()

Under the hood the loader fetches the transcript with the youtube-transcript-api library. That library's own README says YouTube blocks most IP addresses that belong to cloud providers, so on AWS, Google Cloud, Azure or a VPS the request is refused. The loader has no setting for a proxy, so the fix the library offers, rotating residential proxies, means calling the library yourself. The guide on the RequestBlocked error covers that route.

A loader that works from a server

A loader only has to return Document objects. This one gets the transcript over HTTPS from Pipefetch, so it behaves the same on a laptop and in the cloud.

Python
# pip install langchain-core pipefetch
from langchain_core.documents import Document
from pipefetch import NotFoundError, Pipefetch

pf = Pipefetch()  # reads the PIPEFETCH_API_KEY environment variable

def load_youtube(video: str) -> list[Document]:
    try:
        data = pf.transcript(video, segments=False)
    except NotFoundError:
        return []  # the video has no captions; not charged
    return [
        Document(
            page_content=data["text"],
            metadata={
                "source": data["url"],
                "title": data["title"],
                "author": data["channel"]["name"],
                "language": data["language"],
                "publish_date": data["publishedAt"],
                "length": data["durationSeconds"],
            },
        )
    ]

docs = load_youtube("https://www.youtube.com/watch?v=jNQXAC9IVRw")

From here everything is as before: hand docs to your text splitter, vector store or chain. You get a key, with 100 free credits, in the dashboard.

Chunks that link to the moment

For question answering over videos it helps when every chunk knows where in the video it comes from, so an answer can link to the right second. The transcript's timed segments make that a few lines:

Python
def load_youtube_chunks(video: str, seconds: int = 120) -> list[Document]:
    data = pf.transcript(video)
    chunks: dict[int, list[str]] = {}
    for segment in data["segments"]:
        chunks.setdefault(int(segment["start"] // seconds), []).append(segment["text"])
    return [
        Document(
            page_content=" ".join(texts),
            metadata={
                "source": data["url"] + "&t=" + str(index * seconds) + "s",
                "start_seconds": index * seconds,
                "title": data["title"],
            },
        )
        for index, texts in sorted(chunks.items())
    ]

What it costs

One video is one request and 1 credit, whether you load it whole or in chunks. A video without captions costs nothing. The answer also says whether the captions are automatic (isAutoGenerated), which is worth storing: automatic captions have no punctuation and misspell names.

Try it with 100 free credits. No card, no Google Cloud project, no OAuth. Get an API key or read the docs.