Python component

YouTube transcripts in Haystack

GetYouTubeTranscriptFetcher turns YouTube URLs into Haystack Documents, one per video, ready for splitting, embedding and retrieval. Wrap it in a ComponentTool and a Haystack agent can read videos on demand.

Set it up

  1. 1

    Install the component

    Into the same environment as haystack-ai:

    pip install getyoutubetranscript-haystack
  2. 2

    Get an API key

    Sign in at getyoutubetranscript.com and create a key on the developers page (100 free credits, no card). Keys start with sk_live_. Set it as an environment variable:

    export GETYOUTUBETRANSCRIPT_API_KEY=sk_live_...

Index a video in a pipeline

from haystack import Pipeline
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriter
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack_integrations.components.fetchers.getyoutubetranscript import GetYouTubeTranscriptFetcher

store = InMemoryDocumentStore()
indexing = Pipeline()
indexing.add_component("fetcher", GetYouTubeTranscriptFetcher())
indexing.add_component("splitter", DocumentSplitter(split_by="word", split_length=200))
indexing.add_component("writer", DocumentWriter(document_store=store))
indexing.connect("fetcher.documents", "splitter.documents")
indexing.connect("splitter.documents", "writer.documents")
indexing.run({"fetcher": {"videos": ["https://youtu.be/5e37ZT3SQbk"]}})

What you can build

  • RAG over talks and lectures with any Haystack document store.
  • An agent tool: ComponentTool(component=GetYouTubeTranscriptFetcher(timestamps=True), name="youtube_transcript", ...).
  • Batch jobs that skip failures: raise_on_failure=False logs and skips videos without captions.

Links

Questions about Haystack

Can I save the pipeline as YAML?

Yes. The component serializes with to_dict() and from_dict() and keeps the key as an environment variable reference.

What happens when a video has no captions?

By default the run raises. Set raise_on_failure=False to log and skip those videos instead.

What does it cost?

Each transcript, search or channel page uses one credit from your account, and failed requests are not charged. New accounts get 100 free credits, no card, and paid plans add more credits each month.

Use it in your other tools

All integrations