# YouTube Comments Scraper (`leorochasantos/youtube-comments`) Actor

Public YouTube comments scraper — one typed, null-safe row per comment with author, text, likes, replies and timestamp. Search mode finds the videos to pull comments from. No API key, no login.

- **URL**: https://apify.com/leorochasantos/youtube-comments.md
- **Developed by:** [Leonardo Santos](https://apify.com/leorochasantos) (community)
- **Categories:** Videos, Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.29 / 1,000 comment records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## YouTube Comments Scraper

Public YouTube comments in one typed, null-safe dataset: give it a video URL and
get the comment threads — author, text, likes, replies and timestamp, each as a
clean JSON row that maps directly onto YouTube's own public vocabulary
(`commentId`, `videoId`, `publishedAt`, …). A search mode finds the videos to
pull comments from. No API key, no login, no download.

### Why this actor?

- **Comments as data, not HTML** — every comment is a typed row: `commentId`,
  `author`, `text`, `likeCount`, `replyCount`, `publishedAt` plus the parent
  video's title, channel and URL. No DOM scraping, no selectors to break.
- **Typed, null-safe flat rows** — absent optional fields are explicit `null`,
  never dropped rows or crashes. `*Count` fields are integers, not `"1.2K"`
  strings.
- **Price at the floor** — pay per comment (or per search video), and the
  platform usage is on us; there is no compute bill on top.
- **Self-discovering** — `search` mode returns the top matching videos so you
  can pick which videos to pull comments from, then `detail` does the rest.
- **No upstream cost** — the public comments surface needs no key and no
  per-comment fee; you pay only for the delivered, typed rows.

### Input

```json
{
  "mode": "detail",
  "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "maxResults": 50
}
```

`mode` is required — `detail` (comments for one video) or `search` (video rows
for a keyword). `videoUrl` (URL or bare 11-char id) or `query` are required for
their mode. `maxResults` (default 50, hard cap 100) is the total row budget and
is enforced locally — in `detail` mode it is the number of top-level comments;
replies are counted, not enumerated, in v1.

### Output

One row per comment (`detail`) or per video (`search`); `recordType`
discriminates the two:

```json
{
  "recordType": "comment",
  "commentId": "Ugx…",
  "author": "Alice",
  "authorChannelId": "UC…",
  "text": "Great video! Learned a lot.",
  "likeCount": 1200,
  "replyCount": 15,
  "videoTitle": "Never Gonna Give You Up",
  "videoId": "dQw4w9WgXcQ",
  "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "channelId": "UCuAXFkgsw1L7xaCfnd5JJOw",
  "channelName": "Rick Astley",
  "publishedAt": "2026-09-04T…Z",
  "error": null,
  "scraped_at": "2026-09-06T…Z"
}
```

Search rows carry the video shape instead (`recordType: "video"`, `videoTitle`,
`viewCount`, `durationSeconds`). Dataset views (`comments`, `videos`) split the
two shapes for you.

### Pricing

### Pricing

Pay per event, and **the platform usage is on us** — the price you see is the price you pay, with no compute bill on top.

| Event | Price | What one charge buys |
|---|---|---|
| Comment record | **$0.00045** | Charged once per delivered public comment row (detail mode; one dataset row per top-level comment). Rows are charged only after they are pushed to the dataset; a missing or invalid mode/videoUrl, a video with no reachable comments, an empty search, and an upstream bot-wall/5xx/timeout are free error items and never charged. |
| Video record | **$0.00045** | Charged once per delivered public video row (search mode; one dataset row per search result). Rows are charged only after they are pushed to the dataset; errors are free. |
| Actor Start | **$0.002** | One run, whatever it returns. |

Higher Apify subscription tiers pay less on every event (Silver −20%, Gold −35%).

### Use cases

- **Engagement research** — how do viewers react to a launch video? Pull the
  comments with likes and timestamps, no login needed.
- **Community analysis** — topics, sentiment and repeat commenters across your
  own or competitors' video libraries.
- **Content repurposing** — mine the questions and corrections in the comments
  of a video to drive follow-up content.
- **LLM/MCP tooling** — clean, typed JSON with YouTube-native field names; no
  scraping or parsing the site yourself.

### FAQ

**Does this actor need an API key or login?** No. It reads YouTube's public
comments surface; there is no upstream cost. (Reachability from datacenter IPs
is gated on an on-platform probe before this actor goes live.)

**Which comments does `detail` return?** Top-level comment threads — one row per
thread, newest first as YouTube serves them. Each row carries the thread's
public reply count; enumerating replies is not part of v1.

**How many rows can I get?** Up to `maxResults` (default 50, hard cap 100). The
cap is enforced locally before/instead of trusting upstream, so you are never
billed for more than you asked for.

**What is a "record" for billing?** One dataset row — one comment (detail mode)
or one search video (search mode), each a separate PPE event.

**What happens when nothing matches?** A video with no reachable comments, a
search that matches nothing, a missing mode, or an upstream bot-wall becomes a
free error item with the message in the `error` field — never a charged empty
success.

**Is this personal data?** No. Only public comment fields the author chose to
publish — display name, channel id, text, counts and timestamp. No email, no
contact, no account-level data.

***

*This Actor is an independent tool and is not affiliated with, endorsed by, or
sponsored by YouTube or Google LLC. It reads only public comments and video
metadata.*

# Actor input Schema

## `mode` (type: `string`):

What to scrape. One mode per run. `detail` returns the public comments of one video (given by videoUrl). `search` returns the public video rows matching a keyword so you can pick which videos to pull comments from.

## `videoUrl` (type: `string`):

A single video URL (youtube.com/watch?v=...) or bare 11-character video id whose comments you want. Required when mode is `detail`.

## `query` (type: `string`):

Keyword(s) to search for videos. Required when mode is `search`.

## `maxResults` (type: `integer`):

Hard cap on the total rows delivered — the billing boundary, enforced locally before/instead of trusting upstream. In `detail` mode this is the number of top-level comments; replies are counted, not enumerated, in v1.

## `simulate_upstream_botwall` (type: `boolean`):

Debug/test hook: forces a YouTube bot-wall (HTTP 200 with a 'sign in to confirm' challenge) so the free error path can be verified. Never enable in production.

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

Proxy to use for outgoing requests. The comments surface is fetched through the Apify datacenter proxy by default.

## Actor input object example

```json
{
  "mode": "detail",
  "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "query": "apify actor tutorial",
  "maxResults": 50,
  "simulate_upstream_botwall": false,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `results` (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 = {
    "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    "query": "apify actor tutorial"
};

// Run the Actor and wait for it to finish
const run = await client.actor("leorochasantos/youtube-comments").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 = {
    "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    "query": "apify actor tutorial",
}

# Run the Actor and wait for it to finish
run = client.actor("leorochasantos/youtube-comments").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 '{
  "videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "query": "apify actor tutorial"
}' |
apify call leorochasantos/youtube-comments --silent --output-dataset

```

## MCP server setup

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

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/OP7czMX6n4bqsqdLV/builds/bZXz7pVDzHedyAoXi/openapi.json
