# YouTube Comments API - Replies, Likes & Authors (`stas_k/youtube-comments-api`) Actor

Comment scrapers report success on a video whose comments are turned off, so you pay for an empty dataset. This actor reads the watch payload, pages the continuation token and charges only for a comment it delivered.

- **URL**: https://apify.com/stas_k/youtube-comments-api.md
- **Developed by:** [Stas K](https://apify.com/stas_k) (community)
- **Categories:** Social media, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.40 / 1,000 comments

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 Comments API

Give it video urls and get one row per comment: the text, the author, likes, reply count,
whether the channel is verified or the video owner, whether the uploader hearted the
comment, whether it is pinned, the age YouTube prints, and a direct link to the comment.
Replies come as their own rows with `parentCommentId`, and you can ask for the newest
comments first instead of the default "top".

Built for the two ways a comment scraper usually cheats you. It does not come back green
with an empty dataset when a video has its comments turned off: that video gets a free row
that says so. And it does not charge for a comment you cannot use: an emoji-only comment
has no text to sell and is counted, not billed.

### What you pay for

One event, `comment-delivered`, is charged per comment row that lands in the dataset.
Everything else is free and says why in the row's `reason`:

- the line is not a video (`INVALID_VIDEO`), or the same video appeared earlier
  (`DUPLICATE`);
- the watch page exposes no comment section, which is what a closed comment section looks
  like (`NOT_CHECKED_NO_COMMENTS`);
- YouTube answered 404 (`NOT_CHECKED_UNAVAILABLE`) or something else went wrong while
  reading (`NOT_CHECKED_READ_ERROR`);
- the run hit `maxVideos` or `maxCommentsPerVideo` (`NOT_CHECKED_LIMIT`), the spending cap,
  or the platform's clock (`NOT_CHECKED_TIME`);
- the price could not be read (`NOT_CHECKED_BILLING`): the run then reads nothing and
  charges nothing rather than guessing.

A comment that was read but not delivered is never dropped in silence: when the run stops
for time, for the cap or after a charge error, every read comment comes back as its own
free row naming the reason, so `commentsSeen` always adds up.

### What it does not do

- It does not invent an absolute date. YouTube's payload carries a relative age
  ("6 years ago"), so `publishedTimeText` is what you get, and `publishedAt` does not
  exist in the output.
- It does not read replies of replies (YouTube shows one level below a comment).
- It does not log in, so it only reads what a guest sees.
- It does not download video, audio or thumbnails, and it does not translate comments.
- It does not promise every comment of a huge video: `maxCommentsPerVideo` is your budget
  and the run says when it stopped at it.

### Input

`videos` (required): a watch url, a `youtu.be` link, a shorts link or the bare 11
character id, one per line. The schema prefill holds two real videos so the Run button
works without typing anything.

`maxCommentsPerVideo` defaults to 100 (hard ceiling 2000). `sort` is `top` (what the watch
page shows) or `newest`. `includeReplies` defaults to true and `maxCommentsPerThread` to
20\. `maxVideos` defaults to 20 (hard ceiling 200).

A quarter of `maxCommentsPerVideo` is held back for replies, and the leftover space goes
back to the listing. Measured on a live video with 40 rows: 32 top level comments and 8
replies, every reply naming its parent. Without that split a busy video fills the whole
budget with top level comments and never opens a thread, so a title that promises replies
would sell none.

### How it reads, measured on 2026-11-12

The actor talks to YouTube's public `youtubei/v1/next` endpoint over plain HTTP. The same
request answered from a home connection and from our Frankfurt VPS, a datacenter address:

- the watch payload came back at 420 086 bytes and carried the comment section as an
  `itemSectionRenderer` with `sectionIdentifier: "comment-item-section"`;
- that section's continuation token returned 21 comment threads and 20 comment entities,
  284 311 bytes, from both addresses;
- the comment text lives in `frameworkUpdates.entityBatchUpdate`, not inside the thread
  renderer, and like and reply counts are strings ("4.8M") that are parsed into numbers;
- one listing page carries 20 comments, and 10 pages gave 200 unique comments in 4.7
  seconds on our machine;
- the comment toolbar carries a static heart label ("by @channel") on every record, 180
  of 180 on three videos, so it is a state template and not a fact. `heartedByCreator`
  is computed from the creator's thumbnail, which appeared on 4 of 60 comments on one
  video and 0 of 60 on two others, and a test pins the difference;
- `activeFilters` style tricks are not needed: the sort menu tokens for "Top" and "Newest"
  are in the watch payload.

`Comments are turned off.` appears in the page header even on a video with ten million
comments, because the reply box is disabled for a guest. The actor never uses that phrase
as a signal, and a test pins it.

### Notes for integrators

The summary is written under `RUN_SUMMARY` in the run's default key value store, which is
where the schema link points. Fields: `videosRequested`, `videosAttempted`, `videosRead`,
`videosNoComments`, `videosStopped`, `videosFailed`, `commentsSeen`, `commentsDelivered`,
`commentsSkippedNoText`, `commentsDuplicate`, `commentsUndelivered`, `repliesDelivered`,
`pagesRead`, `chargedEvents`, `deliveredUncharged`, `chargeUncertain`, `writeErrors`,
`rowsWritten`, `videosInvalid`, `videosDuplicate`, `videosLimited`, `videosCutByBudget`,
`priceEvent`, `datasetNote`, `byStatus`, `billingActive`, `priceNote`, `stopReason`,
`counterMismatch`, `finishedAt`. `videosRequested` always equals `videosAttempted` plus
`videosStopped` plus the invalid, duplicate and limited lines. `videosCutByBudget` counts
read videos that ran out of their own `maxCommentsPerVideo` budget: it describes an
attempted video and is never added to that sum.

Apache 2.0. Issues and feature requests are welcome on the actor's page.

# Actor input Schema

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

One video per line: a watch url, a youtu.be link, a shorts link or the bare 11 character video id. A line that repeats is free, a line that is not a video comes back as its own free row with the reason.

## `maxCommentsPerVideo` (type: `integer`):

Comments are sold per delivered row, so this is the ceiling that protects your budget. The actor stops reading when it reaches it and says so in the summary.

## `sort` (type: `string`):

top follows the watch page default (most relevant first), newest asks YouTube for the newest comments first.

## `includeReplies` (type: `boolean`):

When on, a quarter of maxCommentsPerVideo is held back for replies and they are read after the top level comments, each as its own row with parentCommentId.

## `maxCommentsPerThread` (type: `integer`):

Replies are sold the same way as comments, so this caps each thread. 0 means replies are not read at all.

## `maxVideos` (type: `integer`):

How many distinct videos this run reads. Lines beyond it come back as a free row with the reason, so a long list cannot spend your budget by accident.

## Actor input object example

```json
{
  "videos": [
    "https://www.youtube.com/watch?v=jNQXAC9IVRw",
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  ],
  "maxCommentsPerVideo": 100,
  "sort": "top",
  "includeReplies": true,
  "maxCommentsPerThread": 20,
  "maxVideos": 20
}
```

# Actor output Schema

## `dataset` (type: `string`):

One row per comment. status is OK when the row carries a comment, or NOT_CHECKED\_\* with the reason in plain words: INVALID_VIDEO (the line is not a video), DUPLICATE (the same video came earlier), NO_COMMENTS (the watch page exposes no comment section, comments may be turned off), UNAVAILABLE (YouTube answered 404), LIMIT (beyond maxVideos or maxCommentsPerVideo), READ_ERROR, TIME, BILLING, and the spending cap stops the run. A comment row carries: videoId, commentId, parentCommentId and isReply (replies are their own rows and are read after the top level comments, into whatever the budget left), author, authorChannelId, authorIsVerified, authorIsCreator, text, likes and likesText (the number parsed, the original text kept beside it), replyCount and replyCountText, heartedByCreator (true only when the comment carries the creator's heart mark; the toolbar label YouTube prints is the same on every record, measured 180 of 180, and is never used as the fact), pinnedText (Pinned by @channel, when YouTube shows it), publishedTimeText, url, input and inputIndex (the line it belongs to), plus videoTitle, videoChannel and videoCommentsCountText. publishedTimeText is what YouTube prints, a relative age like '6 years ago': the payload carries no absolute date, so none is invented. billable is a claim about the price list; the money actually taken is chargedEvents in the summary.

## `summary` (type: `string`):

Run summary. videosRequested is the number of input lines and always equals videosAttempted plus videosStopped plus the invalid, duplicate and limited lines. videosCutByBudget counts read videos that ran out of their own maxCommentsPerVideo budget: it is a property of an attempted video, not a line of input, so it is never added to that sum. commentsSeen counts every comment record the pages carried, and always equals commentsDelivered plus commentsSkippedNoText (an emoji-only comment has nothing to sell and is never charged) plus commentsDuplicate plus commentsUndelivered. chargedEvents is the money really taken, deliveredUncharged a batch that is in the dataset and was not paid for, chargeUncertain a batch whose fate is unknown. byStatus splits the rows by status, pagesRead counts the continuation pages read, repliesDelivered the rows that are replies (a quarter of the budget is held back for them). billingActive, priceNote and priceEvent say how the run stood with the price: null billingActive means the price could not be read, not that billing is off. counterMismatch is true when the numbers above do not add up, countersNote names the gap. stopReason is empty when the list finished.

# 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=jNQXAC9IVRw",
        "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    ]
};

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

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

```

## MCP server setup

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

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/GN5HJTJTXd4EPbwoV/builds/8hdCYcKbN3KcHER5o/openapi.json
