How to Summarise YouTube Transcripts with LlamaIndex

YouTube transcript summarisation in LlamaIndex: EnConvert Distill returns schema-defined fields from up to 50 video URLs in one synchronous call, no scraping

Get API key

A developer building a LlamaIndex pipeline that indexes YouTube video content needs transcript text in clean structured form before it can be built into nodes and queried. YouTube watch pages render the transcript as a JavaScript-driven panel alongside the video player, related video recommendations, and comment sections, and libraries that extract transcripts by scraping the DOM break when YouTube updates its page structure. EnConvert Distill renders the YouTube page, applies a schema the pipeline defines, and returns transcript-focused fields in one synchronous call. The pipeline gets schema-defined transcript content ready to build into TextNodes and index with no additional dependencies.

Example

python
import asyncio
import os

import requests
from llama_index.core import VectorStoreIndex
from llama_index.core.schema import TextNode
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai import OpenAI
from llama_index.core.agent.workflow import FunctionAgent

# LlamaIndex's OpenAI integration reads OPENAI_API_KEY from the environment

BASE_URL = "https://api.enconvert.com/v2"
headers = {
    "X-API-Key": os.environ["ENCONVERT_API_KEY"],
    "Content-Type": "application/json",
}

TRANSCRIPT_SCHEMA = {
    "title": "The video title",
    "transcript_summary": "A three sentence summary of the spoken transcript. Return an empty string if the transcript text is not on the page.",
    "main_topics": "The main topics covered in the transcript, as a list. Return an empty list if the transcript text is not on the page.",
    "key_quotes": "Up to three short quotes copied word for word from the transcript. Return an empty list if the transcript text is not on the page.",
    "video_duration": "The length of the video, as shown on the page",
}


def distill_transcripts(urls: list[str]) -> list[dict]:
    """Return structured transcript fields for up to 50 YouTube watch URLs."""
    if len(urls) > 50:
        raise ValueError("Distill accepts at most 50 URLs per call.")

    # One synchronous call: no job_id, no polling, no download step
    response = requests.post(
        f"{BASE_URL}/distill",
        headers=headers,
        json={"urls": urls, "schema": TRANSCRIPT_SCHEMA},
        timeout=300,
    )

    # Distill runs on paid plans only, and the free tier returns 402
    if response.status_code == 402:
        raise RuntimeError("Distill requires a paid plan.")
    response.raise_for_status()

    videos = []
    for result in response.json()["results"]:
        if result["status"] != "completed":
            print(f"Skipped {result['url']}: {result['status']}")
            continue

        render_quality = result.get("render_quality", 1.0)
        if render_quality < 0.5:
            print(f"Skipped {result['url']}: low render quality ({render_quality})")
            continue

        data = result["data"]  # keys match TRANSCRIPT_SCHEMA exactly

        # Skip a video whose transcript text was not on the page
        if not data.get("transcript_summary"):
            print(f"Skipped {result['url']}: no transcript text found")
            continue

        videos.append({"url": result["url"], **data})
    return videos


def format_video(video: dict) -> str:
    topics = video["main_topics"]
    quotes = video["key_quotes"]
    return (
        f"Source: {video['url']}\n"
        f"Title: {video['title']}\n"
        f"Duration: {video['video_duration']}\n"
        f"Topics: {', '.join(topics) if isinstance(topics, list) else topics}\n"
        f"Quotes: {' | '.join(quotes) if isinstance(quotes, list) else quotes}\n"
        f"Transcript summary: {video['transcript_summary']}"
    )


video_urls = [
    "https://www.youtube.com/watch?v=aircAruvnKk",
    "https://www.youtube.com/watch?v=kCc8FmEb1nY",
    "https://www.youtube.com/watch?v=zjkBMFhNj_g",
]

# Option 1: index the transcript fields as nodes and query them
nodes = [
    TextNode(
        text=format_video(video),
        id_=video["url"],
        metadata={
            "source_url": video["url"],
            "title": video["title"],
            "duration": video["video_duration"],
        },
    )
    for video in distill_transcripts(video_urls)
]

index = VectorStoreIndex(nodes)
query_engine = index.as_query_engine(similarity_top_k=3)
print(query_engine.query("What are the main topics covered across these videos?"))

# Option 2: wrap the function as a tool so an agent can read any video on demand
def summarise_youtube_transcripts(urls: list[str]) -> str:
    """Reads YouTube watch pages and returns transcript fields for each video:
    title, transcript summary, main topics, key quotes, and duration."""
    try:
        return (
            "\n\n---\n\n".join(format_video(v) for v in distill_transcripts(urls))
            or "No transcripts could be read."
        )
    except (ValueError, RuntimeError) as error:
        return str(error)


transcript_tool = FunctionTool.from_defaults(
    fn=summarise_youtube_transcripts,
    name="summarise_youtube_transcripts",
    description="Reads YouTube watch pages and returns transcript fields for each video.",
)

agent = FunctionAgent(
    tools=[transcript_tool],
    llm=OpenAI(model="gpt-4.1"),
    system_prompt=(
        "You answer questions about YouTube videos. Use summarise_youtube_transcripts to read "
        "the videos you need, answer only from what it returns, and cite the video URL for every statement."
    ),
)


async def main():
    response = await agent.run(
        "Read https://www.youtube.com/watch?v=zjkBMFhNj_g "
        "and summarise what the speaker covers."
    )
    print(str(response))


asyncio.run(main())

What you get back

Distill returns transcript-focused schema fields inline as structured JSON in the data object, with no polling, no job_id, and no signed URL to fetch. The render_quality score lets the pipeline skip a video before indexing incomplete content. Extracting YouTube transcripts by scraping the DOM requires maintaining selectors that break on layout changes, and the YouTube Data API returns caption track metadata but requires a separate download step to retrieve the transcript text; Distill returns both the transcript summary and structured fields in one call.

Get free API key — 500 ops per month, no card required. Note: Distill runs on paid plans. Free tier returns 402.