Black Friday · 30% off

Get 30% off
Back to blog
Integrations

Build an AI YouTube Video Summarizer with LangChain and Next.js

A working YouTube summarizer built with LangChain and Next.js: fetch the transcript, chunk it with a text splitter, summarize each chunk, then combine the results into one final summary - full code for every step.

00:08:00 · SEP 26, 2026 · UPDATED OCT 09, 2026

Quick answer

Fetch the transcript via a hosted API, split it into chunks with LangChain's text splitter, summarize each chunk, then combine the chunk summaries into one final summary - the same map-reduce pattern that keeps this working on a 3-hour video, not just a 5-minute one.
01

Install LangChain

This tutorial uses the current LangChain JS package split - core primitives, the OpenAI integration, and text splitters each live in their own package:

npm install langchain @langchain/core @langchain/openai @langchain/textsplitters
02

Fetch the transcript

Get a key from the dashboard (100 free credits, no card required), then call the transcript endpoint from a Next.js route handler:

// app/api/summarize/route.ts
import { NextResponse } from 'next/server';

async function fetchTranscript(videoId: string) {
  const res = await fetch(
    `https://getyoutubetranscript.com/api/v1/transcript?v=${videoId}`,
    { headers: { Authorization: `Bearer ${process.env.GETYOUTUBETRANSCRIPT_API_KEY}` } }
  );
  const json = await res.json();
  if (!json.success) throw new Error(json.message);
  // json.data.transcript is the full plain-text transcript,
  // json.data.word_count is its length in words.
  return json.data as { transcript: string; word_count: number; title: string };
}

transcript is the full plain-text transcript and word_count is its length - useful for deciding whether to skip the chunking step entirely on a short video.

03

Split the transcript into chunks

A long transcript can easily exceed what's comfortable to send an LLM in one prompt, so split it first. RecursiveCharacterTextSplitter tries to break on paragraph, then sentence, then word boundaries, in that order, so chunks stay readable rather than cutting mid-sentence:

import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';

const splitter = new RecursiveCharacterTextSplitter({
  chunkSize: 4000,
  chunkOverlap: 200,
});

const chunks = await splitter.splitText(transcript);
// A 20-minute video is usually 1-2 chunks; a 2-hour one might be 8-10.

chunkOverlap keeps a little context from the end of one chunk at the start of the next, so a sentence split across the boundary isn't lost to either chunk.

04

Summarize each chunk

ChatPromptTemplate + a model + StringOutputParser piped together (LangChain's expression language, LCEL) is the current, stable way to build a chain - each chunk gets its own short summary in parallel:

import { ChatOpenAI } from '@langchain/openai';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { StringOutputParser } from '@langchain/core/output_parsers';

const model = new ChatOpenAI({ model: 'gpt-4.1-mini', temperature: 0 });

const chunkPrompt = ChatPromptTemplate.fromTemplate(
  'Summarize this part of a video transcript in 3-4 sentences, keeping any concrete facts, numbers, or names:\n\n{chunk}'
);
const chunkChain = chunkPrompt.pipe(model).pipe(new StringOutputParser());

const chunkSummaries = await Promise.all(
  chunks.map((chunk) => chunkChain.invoke({ chunk }))
);

Running these in parallel with Promise.all matters for latency: a 10-chunk transcript summarized one-by-one takes 10x as long as summarizing all 10 at once.

05

Combine the chunk summaries into one

The chunk summaries are short enough now to fit in a single prompt together, so a second chain combines them into the final result:

const finalPrompt = ChatPromptTemplate.fromTemplate(
  'These are summaries of consecutive parts of the same video transcript, titled "{title}".\n' +
  'Combine them into one coherent summary (a short paragraph, then 3-5 key takeaways as bullet points):\n\n{summaries}'
);
const finalChain = finalPrompt.pipe(model).pipe(new StringOutputParser());

const summary = await finalChain.invoke({
  title,
  summaries: chunkSummaries.join('\n\n'),
});

return NextResponse.json({ summary });

This two-pass structure (summarize chunks, then summarize the summaries) is what LangChain's own map-reduce pattern does under the hood - written out explicitly here instead of using a legacy helper chain, since summarization-chain helper APIs have changed across LangChain versions and plain LCEL primitives are the more stable foundation to build on.

06

Why fetch the transcript from an API instead of scraping it yourself

The transcript-fetching step above is the one part of this pipeline that gets genuinely harder in production - self-hosted scraping libraries commonly get blocked once deployed to a cloud server. A hosted YouTube Transcript API is built specifically to keep that step working so the rest of this pipeline doesn't have to think about it.

Full endpoint reference, authentication, and rate limits are in the API docs. Get a key with 100 free credits from the dashboard to try this end to end.

LangChain summarizer FAQs

Q01

Do I need to chunk short videos too?

Not necessarily - check word_count from the transcript response first. A 10-minute video's transcript is usually well under what a single modern LLM prompt can hold, so you can skip straight to one summarization call and skip the chunking/combining steps entirely.

Q02

Why RecursiveCharacterTextSplitter instead of a fixed character split?

A fixed split cuts wherever the character count lands, potentially mid-sentence or mid-word. RecursiveCharacterTextSplitter tries paragraph breaks first, then sentences, then words, only falling back to a hard cut if it has to - so chunks stay coherent for the model to summarize.

Q03

Can I use a different LLM provider instead of OpenAI?

Yes - LangChain's chat model classes share the same interface, so swapping ChatOpenAI for another provider's LangChain integration (Anthropic, Google, etc.) doesn't change anything else in the pipeline.

Q04

Why pipe a prompt, model, and output parser together instead of using LLMChain?

LLMChain is LangChain's older chain-building API. The piped/LCEL style (prompt.pipe(model).pipe(parser)) is the current recommended pattern - it composes more predictably and is what LangChain's own newer documentation builds around.

Q05

What does this cost to run?

Two costs: the LLM calls (one per chunk, plus one to combine - billed by your model provider), and 1 credit per transcript fetch from the transcript API. 100 free credits cover the fetch side while testing.

Q06

What happens if the video has no transcript at all?

The transcript endpoint returns a clear error code (TRANSCRIPT_DISABLED or TRANSCRIPT_NOT_FOUND) rather than an empty string - check for success: false before handing anything to the text splitter, since summarizing an empty transcript wastes an LLM call for nothing.

Related

Featured on aitoolfame.comFeatured on Aura++Featured on DeepLaunch.ioFeatured on Dofollow.ToolsFeatured on EasyDoFollowFeatured on EarlyHuntFeatured on Findly.toolsFeatured on FoundrListGood AI ToolsFeatured on IndieHuntFeatured on LaunchBuffFeatured on launched.toolsFeatured on Launch Llama ToolsFeatured on LemonLaunchLiftOff launch badgeMy Launch StashGetYouTubeTranscript on Nick LaunchesOpenHunts Club MemberFeatured on saasfame.comShinyLaunchFeatured on ShowMeBestAIFeatured on toolfame.comListed on Turbo0Featured on Twelve ToolsHuzzler Embed BadgeFeatured on CodeHypeGetYouTubeTranscript on Better LaunchDokeyAIFeatured on WayfindioFeatured on LaunchZoneFeatured on NoonlaunchFeatured on WhatsthebigdataSurfaced on CodeTrendyFeatured on ScrollLaunchFeatured on ufind.bestFeatured on ShipBoostProduct WingWe Like ToolsAppa ListAcid ToolsPower Up ToolsToshi ListAIGC 160Appsy ToolsHunt for ToolsBeam ToolsTool Find DirTool SignalSaaS Tools DirSoftware BoltProduct List DirStack DirectorySaaS FieldSaaS WheelSaaS RootsStartup BenchmarksUnite ListTrustinerBest Tool VaultSolver ToolsAsh ListSmart Kit HubAI X CollectionAI Tech ViralMillion Dot HomepageThat App ShowLaunch ScrollMy Start ToolsLatest AI UpdatesSuper AI BoomTools Under RadarThe Key ToolsTool JourneyTools List HQThe App ToolsThe Mega ToolsSource DirTool CosmosTop Trend ToolsTiny Tool HubTool PrismStartup AIdeasFeatured on WonderLaunchFeatured on ShipycornFeatured on ToolsClawListed on ProofStoriesFeatured on ToolListedLaunched on Launch Streak