YouTube Transcript Scraper & API - Chunked for RAG avatar

YouTube Transcript Scraper & API - Chunked for RAG

Pricing

from $5.00 / 1,000 transcripts

Go to Apify Store
YouTube Transcript Scraper & API - Chunked for RAG

YouTube Transcript Scraper & API - Chunked for RAG

YouTube transcripts that arrive already chunked for RAG, each chunk carrying a youtu.be?t= link back to the second it was said. Also an MCP server: get_transcript and get_chunks from Claude or Cursor. Videos, channels, playlists, searches. Never charges for a video it could not transcribe.

Pricing

from $5.00 / 1,000 transcripts

Rating

0.0

(0)

Developer

Darius Andrei

Darius Andrei

Maintained by Community

Actor stats

0

Bookmarked

1

Total users

0

Monthly active users

2 months ago

Last modified

Categories

Features

Limited permissionsSingle-tenantServer interface

Share

YouTube Transcripts for RAG

Transcripts that arrive already chunked, with a timestamp link on every chunk — and you are never charged for a video that did not come back.

A failed video still gets you a row, with a code saying whether the video has no captions or whether we broke. Both are free. Only a delivered transcript is billed.

Most YouTube transcript scrapers hand you one long string. You then write the splitter, the overlap logic and the "where in the video did this come from" bookkeeping yourself — and that bookkeeping is the part that decides whether your RAG answers can cite anything.

This actor does that half. Each chunk comes back with its own https://youtu.be/<id>?t=<s> link, so a retrieved chunk is a clickable jump to the second it was said. Chapters from the video description are used as chunk boundaries when the video has them.

What comes back

Real output, trimmed — one video, chunkSize: 512:

{
"videoId": "aircAruvnKk",
"title": "But what is a neural network? | Deep learning chapter 1",
"channel": "3Blue1Brown",
"status": "success",
"language": "en",
"languageSource": "manual",
"durationSeconds": 1120,
"chunks": [
{
"index": 0,
"text": "This is a 3. It's sloppily written and rendered at an extremely low resolution of 28x28 pixels, but your brain has no trouble recognizing it as a 3...",
"startSec": 4.22,
"endSec": 106.04,
"startUrl": "https://youtu.be/aircAruvnKk?t=4",
"tokenCount": 436,
"chapterTitle": "Introduction example"
},
{
"index": 1,
"text": "This video is just going to be devoted to the structure component of that, and the following one is going to tackle learning...",
"startSec": 95.36,
"endSec": 214.16,
"startUrl": "https://youtu.be/aircAruvnKk?t=95",
"tokenCount": 504,
"chapterTitle": "Series preview"
}
]
}

startUrl is the field that matters. Store it beside the vector and your answers cite a second of video instead of a video.


Worked example: a transcript you can cite

Fetch a video, chunk it, embed it, ask a question, print the answer with a link back to the moment it was said.

$npm i apify-client openai
import { ApifyClient } from 'apify-client';
import OpenAI from 'openai';
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const openai = new OpenAI();
const embed = async (texts) => {
const res = await openai.embeddings.create({ model: 'text-embedding-3-small', input: texts });
return res.data.map((d) => d.embedding);
};
// 1. Run the actor and take its dataset.
const run = await client.actor('darius.c.andrei/youtube-transcripts-rag').call({
startUrls: [{ url: 'https://www.youtube.com/watch?v=ZPUtA3W-7_I' }],
chunkSize: 512,
chunkOverlap: 64,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
// 2. Keep the successes. An error row has no `transcript` key at all, so this
// filter is the whole guard — there is no empty string to sneak through.
const chunks = items
.filter((item) => item.status === 'success')
.flatMap((item) => item.chunks);
// 3. Embed. The chunking already happened; there is no splitter to write.
const vectors = await embed(chunks.map((c) => c.text));
const [query] = await embed(['what did he say about democracy?']);
// 4. Nearest chunk.
const cosine = (a, b) => {
let dot = 0, na = 0, nb = 0;
for (let i = 0; i < a.length; i += 1) { dot += a[i] * b[i]; na += a[i] ** 2; nb += b[i] ** 2; }
return dot / (Math.sqrt(na) * Math.sqrt(nb) || 1);
};
const best = chunks[vectors.map((v) => cosine(v, query)).reduce((m, s, i, arr) => (s > arr[m] ? i : m), 0)];
// 5. The point of the whole thing: the answer carries a seekable citation.
console.log(best.text);
console.log(`watch it: ${best.startUrl}`, best.chapterTitle ? `· ${best.chapterTitle}` : '');
Democracy is in the DNA of India, it is not a gift of any constitution...
watch it: https://youtu.be/ZPUtA3W-7_I?t=1260 · Democracy

Swap step 4 for Pinecone, Chroma, pgvector or whatever you already run — the chunk is already the unit you store, and startUrl is the metadata field you keep beside it.

This example lives in examples/rag-quickstart.mjs and is covered by examples/rag-quickstart.test.mjs, which runs it on every test pass with the two API calls stubbed, so the field names and the citation line cannot drift from the code.

Chunk fields

fieldtypemeaning
indexnumberposition in the video, from 0
textstringthe chunk
startSecnumberwhen it starts, in seconds
endSecnumberwhen it ends
startUrlstringhttps://youtu.be/<id>?t=<startSec> — the citation
tokenCountnumberapproximate tokens (words / 0.75)
chapterTitlestringpresent only when the video has chapters

Chunk sizes are in approximate tokens, not characters, and not a tokenizer's tokens: we ship no tokenizer, because its vocabulary would have to match whichever model you embed with. Caption segments are atomic — a chunk ends on a segment boundary, so the real size lands near chunkSize rather than on it.


Input

startUrls takes {"url": "..."} objects or bare strings. Five shapes work:

// one video
{ "startUrls": [{ "url": "https://www.youtube.com/watch?v=ZPUtA3W-7_I" }] }
// several videos
{ "startUrls": [
{ "url": "https://www.youtube.com/watch?v=ZPUtA3W-7_I" },
{ "url": "https://youtu.be/dQw4w9WgXcQ" },
{ "url": "aqz-KE-bpKQ" } // a bare video id is fine
] }
// a whole channel, by handle or by id
{ "startUrls": [{ "url": "https://www.youtube.com/@veritasium" }], "maxVideos": 200 }
// a playlist
{ "startUrls": [{ "url": "https://www.youtube.com/playlist?list=PL..." }], "maxVideos": 100 }
// a search
{ "startUrls": [{ "url": "https://www.youtube.com/results?search_query=rag+pipelines" }] }

A watch URL that happens to carry a &list= is treated as the single video, not the playlist.

fielddefaultwhat it does
startUrls—required
maxVideos50per input URL. Caps the paging too, so a lower number is a faster run
language[]preferred codes, best first (en, pt-BR). Empty = the video's own
languageFallbacktranslatedtranslated / auto-generated / manual-only
outputFormats["text"]text, json, srt, vtt
includeChunkstruethe chunks above
chunkSize512approximate tokens
chunkOverlap64approximate tokens, clamped to half the chunk size
chunkBoundarysentencesentence / chapter / none
proxyConfigurationApify residentialleave it alone — see below

Why the proxy default is residential

Measured, not assumed. Through datacenter addresses a run returns about twenty transcripts and then every request after that is Sign in to confirm you're not a bot — including a re-run of the same twenty video IDs seven minutes later, so it is the address pool burning rather than anything about the videos. On residential, 200 videos returned 197 transcripts and 3 real NO_CAPTIONS, with nothing failing on our side.

The proxy cost is already inside the $0.005. Turning it off is the configuration that does not work.

Limits worth knowing before you set maxVideos

These are YouTube's, not ours, and they are measured:

  • A channel or playlist stops paging at 200 pages, about 20,000 videos. Page 200 comes back without a continuation token. Not an error, not a throttle — the end of the road.
  • A search goes dry at roughly 210–260 results, with page sizes tapering off.
  • A channel expands through its uploads playlist, so shorts and past livestreams are included. The /videos tab would filter them out and does not page, so there is no "long-form only" option today. If you need one, say so and it gets built.

Set maxVideos above these and the run logs what it could not reach rather than pretending the number was met.


Output: the dataset row

One row per requested video. The shape is stable and changes additively — fields get added, existing fields do not change meaning or type. Build a pipeline on it.

fieldtypepresentmeaning
videoIdstringalwaysempty on an error against a URL that never resolved to a video
urlstringalwaysthe watch URL; on an unresolvable input, the string you pasted
status"success" | "error"always
titlestringsuccess
channelstringsuccess
durationSecondsnumber | nullsuccessnull when YouTube omits lengthSeconds
languagestringsuccessthe language delivered — the target when translated
languageSourcestringsuccessmanual, asr (auto-generated), or translated
transcriptstringonly if text is in outputFormatsthe plain transcript
segmentsarrayonly if json is in outputFormats{ start, end, text }, seconds
chunksarrayonly if includeChunksthe table above
chaptersarraysuccessfrom description timestamps; [] when there are none
srtstringonly if srt is in outputFormats
vttstringonly if vtt is in outputFormats
errorobjecterror{ code, reason, ourFault }
metaobjectsuccess{ client, bytes, segmentCount } — diagnostics

Three things that will bite a pipeline written from a guess:

  1. transcript, segments and chunks are conditional. Ask for only SRT and you do not pay dataset size for a plain-text duplicate — and you do not get a transcript key.
  2. An error row has no transcript key at all. Not an empty string. An empty string is what an ingestion pipeline swallows silently and embeds as nothing.
  3. durationSeconds can be null.

Error codes

Every code is one of two kinds, and error.ourFault says which:

codeourFaultmeaning
NO_CAPTIONSfalsethe video has no caption track — including one that is nothing but [Music]
LIVE_NO_CAPTIONSfalsea stream that is live right now. It may get captions when it ends
LANGUAGE_UNAVAILABLEfalsecaptions exist, but not in a language your settings accept
AGE_RESTRICTEDfalse"Sign in to confirm your age"
VIDEO_PRIVATEfalsethe uploader set it to private
MEMBERS_ONLYfalsebehind a channel membership
REGION_BLOCKEDfalsenot playable from the country the request came from
VIDEO_UNAVAILABLEfalsedeleted, never existed, or otherwise gone
INVALID_URLfalsenot a YouTube URL, or a target that does not exist
FETCH_FAILEDtruewe broke, after exhausting both client tiers
BOT_CHECK_FAILEDtrueYouTube asked us to sign in. Ours to fix, not yours

VIDEO_PRIVATE, MEMBERS_ONLY and REGION_BLOCKED are classified from YouTube's own refusal text. We have not yet caught one in the wild to confirm the wording still matches — a video that lands in none of them comes back as VIDEO_UNAVAILABLE, so a walled video is always reported as unavailable rather than as a transcript you did not get.

NO_CAPTIONS is a fact about the video. FETCH_FAILED is our fault. You are never charged for either. A competitor returning an empty string for both is why their users cannot tell a dead video from a dead scraper.

Was the run complete?

The RUN_SUMMARY record in the run's key-value store, so you do not have to parse logs:

{ "startUrls": 1, "attempted": 200, "succeeded": 193, "failed": 7,
"skipped": 0, "ourFailures": 0, "charged": 193,
"warnings": ["https://www.youtube.com/playlist?list=PL...: 26 unavailable videos are hidden"] }

ourFailures is the health number. Expansion warnings land here and in the log, and deliberately not in the dataset: the dataset is what you embed, and a warning row would be ingested as if someone had said it in a video.


Pricing

$5.00 per 1,000 transcripts — $0.005 each, with the first hour of every video included.

eventpricefires on
Transcript delivered$0.005one per video that came back with a transcript
Extra video-hour$0.005each started hour past the first — a 3-hour podcast adds 2

Most videos never reach the second line. A 58-minute lecture is $0.005 flat. The surcharge exists because a three-hour podcast moves roughly fifteen times the bytes of an average video, and one flat price would mean quietly refusing to serve the long ones.

  • No actor-start fee. A run that returns nothing costs nothing.
  • A failed video is free. The charge fires on a delivered transcript and nothing else — no captions, age wall, our own failure: all free. A failed long video is free too: the surcharge rides on the transcript charge and cannot fire without it.
  • A resumed run does not re-bill. What was charged is written down before it is charged, so a platform migration mid-run cannot bill a video twice — or surcharge it twice.
  • Your cost limit is a real stop. Set a maximum cost per run and the actor stops fetching when it is reached, rather than scraping the rest of the channel for free and handing you a short dataset with no explanation. The run log says it stopped and why.

MCP: use it from Claude or Cursor

The actor runs in Standby mode and serves MCP over POST /mcp.

{
"mcpServers": {
"youtube-transcripts": {
"type": "http",
"url": "https://darius-c-andrei--youtube-transcripts-rag.apify.actor/mcp",
"headers": { "Authorization": "Bearer YOUR_APIFY_TOKEN" }
}
}
}

Two tools, and only two:

toolarguments
get_transcripturl, lang?
get_chunksurl, chunkSize?, overlap?, lang?

Both are single-video on purpose. A channel or playlist URL is refused with a message telling you to run the actor instead. An MCP call that quietly starts a 4,000-video job is a surprise bill, and we would rather say no.


Questions people arrive with

"My scraper worked and now every request says Sign in to confirm you're not a bot." Your IP pool is burnt, not your code. Measured here: through datacenter addresses a run returns about twenty transcripts and then every request fails — including a re-run of the same twenty video IDs seven minutes later. Same videos, same code, different outcome, so it is the address and not the request. Through residential addresses the same 200 videos returned 197 transcripts. There is no header, client or delay that fixes a burnt pool.

"Is this an alternative to the youtube-transcript-api Python library?" For bulk, yes, and for the same reason: that library runs from your IP, which is exactly the thing that gets blocked. This runs through rotating residential addresses with the cost already inside the per-transcript price. For a handful of videos from your laptop, the library is free and fine — use it.

"Do I get charged when a video has no captions?" No. The charge fires on a delivered transcript and nothing else. You still get a row with an error code, so your pipeline can tell a video that has no captions from a scrape that failed.

"Can it do a whole channel?" Yes — channel, playlist or search URL, up to YouTube's own ceiling of about 20,000 videos. See the limits section for where YouTube stops paging.

"Does it handle videos in other languages?" It returns the language the video is actually in, and can translate when you ask. Getting this right is harder than it sounds: YouTube lists caption tracks alphabetically, not original-language-first, so a naive reader hands you a 3Blue1Brown video in Arabic.

What this does not do

Stated here rather than discovered later:

  • No retry or backoff on a transient HTTP error. Nothing in hundreds of measured videos hit one, so it has not been built, and advertising an untested branch as resilience is how reliability claims become refund requests.
  • No "long-form only" channel filter. See the limits section.
  • No tokenizer. Chunk sizes are approximate tokens.
  • No private, members-only or region-locked videos. Nothing signs in.