# YouTube Transcript (RAG-ready) (`xiaoliang527/youtube-transcript-rag`) Actor

YouTube transcripts for LLM, RAG and AI agents: videos, playlists and channels, split by chapter in Markdown with token counts. Pay only for transcripts returned — failed videos are free.

- **URL**: https://apify.com/xiaoliang527/youtube-transcript-rag.md
- **Developed by:** [xiao liang](https://apify.com/xiaoliang527) (community)
- **Categories:** AI, Videos, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$5.00 / 1,000 transcripts

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## YouTube Transcript (RAG-ready)

Get clean transcripts from YouTube videos, playlists and channels — already split by chapter, in Markdown, with token counts. Built for people feeding YouTube into LLMs, RAG pipelines and AI agents.

**You only pay for transcripts that are actually returned.** Videos without captions, private or deleted videos are reported but never charged.

### What you get for each video

| Field | Description |
|---|---|
| `status` | `ok`, `no_captions`, `unavailable` or `error` |
| `language`, `is_generated` | Caption language and whether it is auto-generated |
| `segments` | `[{start, dur, text}]` with timestamps in seconds |
| `plain_text` | Full transcript as one string |
| `markdown_by_chapter` | `# Title` + `## Chapter` sections — ready for chunking |
| `token_count` | Tokens (cl100k_base), so you can budget LLM calls |
| `meta` | Title, channel, duration, upload date, view count, chapters |

### Input

- **Videos, playlists or channels** — any mix of video URLs, 11-character IDs, playlist URLs or channel URLs (`https://www.youtube.com/@handle`).
- **Preferred languages** — e.g. `["en", "de"]`. Falls back to any available language.
- **Max videos per playlist/channel** — latest N videos.
- **Include metadata and chapters** — on by default.
- **Bypass cache** — results are cached for 7 days; turn this on to always fetch fresh.

```json
{
  "videos": ["https://www.youtube.com/watch?v=kCc8FmEb1nY", "https://www.youtube.com/@3blue1brown"],
  "languages": ["en"],
  "maxPerSource": 20
}
```

### Example output

```json
{
  "video_id": "aircAruvnKk",
  "status": "ok",
  "language": "en",
  "is_generated": false,
  "token_count": 3817,
  "markdown_by_chapter": "# But what is a neural network? | Deep learning chapter 1\n\n## Introduction example\n\n...",
  "meta": {"title": "But what is a neural network? | Deep learning chapter 1", "channel": "3Blue1Brown", "chapters": [{"title": "Introduction example", "start": 0}]}
}
```

### Why this Actor

- **Chapter-aware Markdown** — `markdown_by_chapter` follows the video's own chapters, so chunks for RAG keep their meaning.
- **Token counts included** — budget LLM calls before you send anything.
- **No charge for failures** — no captions, private or deleted videos are returned with a status and are free.
- **Videos, playlists and channels** in one input; preferred language with automatic fallback.

### Use it from code, n8n or an AI agent

Full runnable examples (LangChain, LlamaIndex, MCP, Python, JS): [github.com/1359484419/youtube-transcript-rag-examples](https://github.com/1359484419/youtube-transcript-rag-examples)

#### Python

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("xiaoliang527/youtube-transcript-rag").call(
    run_input={"videos": ["https://www.youtube.com/watch?v=aircAruvnKk"], "languages": ["en"]}
)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    if item["status"] == "ok":
        print(item["meta"]["title"], item["token_count"])
```

#### JavaScript / TypeScript

```js
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('xiaoliang527/youtube-transcript-rag').call({
  videos: ['https://www.youtube.com/@3blue1brown'], maxPerSource: 10,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

#### LangChain (RAG)

```python
from langchain_apify import ApifyDatasetLoader  # pip install langchain-apify
from langchain_core.documents import Document
from apify_client import ApifyClient

run = ApifyClient("<YOUR_APIFY_TOKEN>").actor("xiaoliang527/youtube-transcript-rag").call(
    run_input={"videos": ["https://www.youtube.com/watch?v=kCc8FmEb1nY"]})
docs = ApifyDatasetLoader(
    dataset_id=run["defaultDatasetId"],
    apify_token="<YOUR_APIFY_TOKEN>",
    dataset_mapping_function=lambda i: Document(
        page_content=i.get("markdown_by_chapter", ""),
        metadata={"video_id": i["video_id"], "title": (i.get("meta") or {}).get("title")}),
).load()
## split by "## " headings and index into your vector store
```

#### Claude, Cursor and other MCP clients

Add the Apify MCP server and enable this Actor as a tool:

```json
{
  "mcpServers": {
    "apify": {
      "url": "https://mcp.apify.com?tools=xiaoliang527/youtube-transcript-rag",
      "headers": { "Authorization": "Bearer <YOUR_APIFY_TOKEN>" }
    }
  }
}
```

Then ask: *"Summarize the chapters of https://youtu.be/aircAruvnKk"*.

#### n8n / Make / Zapier

Use the official Apify node or app → **Run Actor** → `xiaoliang527/youtube-transcript-rag` → **Get dataset items**.

### Pricing

**$0.005 per transcript returned** ($5 per 1,000). Nothing is charged for videos without captions, private, deleted or invalid videos. Results are cached for 7 days, so re-running the same video returns instantly.

### FAQ

**Does it work for auto-generated captions?** Yes — `is_generated` tells you which kind you got.

**Can I choose the language?** Pass `languages` in order of preference, e.g. `["de", "en"]`. If none is available, the first available language is returned.

**Shorts and live replays?** Supported when they have captions.

### Reliability

Every day a regression set of real videos runs against the live Actor; failures by type (blocked, no captions, unavailable) are tracked so breakages are fixed fast.

### Limits

Only public captions are returned. The Actor does not download audio or video, does not transcribe audio, and does not access private, members-only or age-restricted content.

# Actor input Schema

## `videos` (type: `array`):

Video URLs/IDs, playlist URLs or channel URLs (@handle).

## `languages` (type: `array`):

Language codes in order of preference; falls back to any available.

## `maxPerSource` (type: `integer`):

How many latest videos to take from each playlist or channel.

## `includeMeta` (type: `boolean`):

Adds title, channel, duration, upload date and chapters; chapters are used to split the Markdown.

## `proxyConfiguration` (type: `object`):

Residential proxy is recommended; YouTube blocks most datacenter IPs.

## `noCache` (type: `boolean`):

Always fetch fresh transcripts instead of using the 7-day cache.

## Actor input object example

```json
{
  "videos": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "languages": [
    "en"
  ],
  "maxPerSource": 50,
  "includeMeta": true,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  },
  "noCache": false
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "videos": [
        "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("xiaoliang527/youtube-transcript-rag").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "videos": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"] }

# Run the Actor and wait for it to finish
run = client.actor("xiaoliang527/youtube-transcript-rag").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "videos": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ]
}' |
apify call xiaoliang527/youtube-transcript-rag --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,xiaoliang527/youtube-transcript-rag"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/COtru0MBhPhLvBc1z/builds/VgeTG47xCLHYJyTgY/openapi.json
