I run Serpent, the API used in the examples below.
To get YouTube comments in Python or Node, send one GET request with the video link, then follow the cursor for the next page. Google's official Data API does the same job with a Google Cloud API key and a default quota of 10,000 units a day. Both routes are shown below.
Short answer: If you are happy to set up a Google Cloud project and keep an eye on a daily quota, YouTube's Data API is free and returns exact dates and like counts, so use it. If you would rather make one call with one key and no project to set up, a comments API like the one below is less to wire up. One call returns one page of comments (20 in each answer saved for this post), not one comment, and sort=newest is the order to use when you need a walk you can run again. A new key comes with 10 free calls, and the pricing page has the rest.
The Serpent output below comes from answers my API returned on 29 November 2026, saved before launch, with the comment text and handles replaced by invented ones. The Google facts come from Google's documentation pages, which I read on 24 November 2026. Serpent is not affiliated with YouTube or Google.
What are the two ways to get YouTube comments in code?
One is YouTube's own Data API v3, a free service from Google. The other is a comments API, which is what I sell. Both routes return JSON. They differ in the credential you need, how many comments come back per call, how ordering and paging work, and whether dates and like counts arrive exact or as shown.
How does the official YouTube Data API route work?
You call the commentThreads.list method with part=snippet, a videoId and a key from a Google Cloud project that has the YouTube Data API enabled. Google's getting-started page says unauthorized list requests retrieve only public data, which covers comments on public videos.
The cost is quota. Google's quota page lists commentThreads.list at 1 unit and gives a default of 10,000 units a day. Every extra page costs the same unit. maxResults takes 1 to 100 and defaults to 20, so at 100 per call the whole default quota is 10,000 calls, or up to 1,000,000 top-level comments a day if nothing else in your project spends units.
Ordering is order=time (the default) or order=relevance. For the next page you send the previous response's nextPageToken back as pageToken. Each thread carries only a limited number of replies; to get the rest you call comments.list with parentId, at another unit per call.
Example code, not run (it needs your own Google key, and I made no call to Google's API for this post). The field names follow the documentation for the commentThread and comment resources.
import requests
KEY = "YOUR_GOOGLE_API_KEY"
HOST = "https://www.googleapis.com"
URL = HOST + "/youtube/v3/commentThreads"
params = {
"part": "snippet",
"videoId": "dQw4w9WgXcQ",
"maxResults": 100,
"order": "relevance",
"textFormat": "plainText",
"key": KEY,
}
data = requests.get(URL, params=params, timeout=60).json()
for item in data.get("items", [])[:3]:
c = item["snippet"]["topLevelComment"]["snippet"]
print(c["likeCount"], item["snippet"]["totalReplyCount"], c["publishedAt"], c["authorDisplayName"])
print(" ", c["textDisplay"])
# Next page: send this value back as the pageToken parameter
print("nextPageToken:", data.get("nextPageToken"))
The same request in Node 18 or later, saved as official.mjs. Also example code, not run:
const KEY = "YOUR_GOOGLE_API_KEY";
const HOST = "https://www.googleapis.com";
const URL_BASE = HOST + "/youtube/v3/commentThreads";
const params = new URLSearchParams({
part: "snippet",
videoId: "dQw4w9WgXcQ",
maxResults: "100",
order: "relevance",
textFormat: "plainText",
key: KEY,
});
const data = await (await fetch(`${URL_BASE}?${params}`)).json();
for (const item of (data.items || []).slice(0, 3)) {
const c = item.snippet.topLevelComment.snippet;
console.log(c.likeCount, item.snippet.totalReplyCount, c.publishedAt, c.authorDisplayName);
console.log(" ", c.textDisplay);
}
// Next page: send this value back as the pageToken parameter
console.log("nextPageToken:", data.nextPageToken);
This route has real strengths. publishedAt is an exact date and time, and likeCount is an exact count. The friction is the project and key, a quota shared by every call your project makes, and a video with comments turned off, which Google's documentation says answers with a 403 commentsDisabled error that your code has to catch.
How do you get comments with one call in Python?
Send a GET request to https://apiserpent.com/api/social/youtube/comments with your key in the X-API-Key header. video is required and takes an 11-character id or a YouTube link. sort is top or newest, and cursor is the next_cursor from the previous page. One call returns one page of top-level comments, and each answer saved for this post held 20.
Install requests, put your key in place of the placeholder, and use this:
import requests
API_KEY = "sk_live_your_api_key"
BASE = "https://apiserpent.com/api/social/youtube/comments"
def get_page(video, sort="top", cursor=None):
params = {"video": video, "sort": sort}
if cursor:
params["cursor"] = cursor
r = requests.get(BASE, params=params, headers={"X-API-Key": API_KEY}, timeout=60)
r.raise_for_status()
return r.json()
page = get_page("https://www.youtube.com/watch?v=dQw4w9WgXcQ", sort="top")
if not page.get("comments"):
print("No comments came back for this video")
else:
print(page["video_id"], "| sort:", page["sort"], "| total_comments:", page["total_comments"])
for c in page["comments"][:3]:
print(f'{c["like_text"]:>5} likes | {c["reply_count"]:>4} replies | {c["published"]} | {c["author"]}')
print(" " + c["text"].replace("\n", " "))
print("more pages:", "yes" if page.get("next_cursor") else "no")
The output below is the code above run with only the HTTP request swapped for the saved file. The saved copy keeps the first two of the 20 comments the call returned, so the loop prints two comments where a full answer would print three.
dQw4w9WgXcQ | sort: top | total_comments: 2462804
128K likes | 702 replies | 7 years ago | @viewer1
Came back to hear this one more time
73K likes | 728 replies | 7 years ago | @viewer2
My study group shared this link instead of the notes
more pages: yes
The page-level fields are video_id, total_comments, comments_disabled, sort, next_cursor and the comments list. total_comments is the count shown at the time (2,462,804 here) and it appears on the first page only: on page two of the same walk it was null. The 128K and 73K are like_text, the label as displayed.
The code tests the comments list, not the HTTP status, because a video with nothing to give still answers normally. Three saved answers show it. A video with comments turned off came back with comments_disabled true, an empty comments list and a null next_cursor. A removed video and a well-formed id for a video that does not exist came back the same way, with comments_disabled false. A value that is not a video id or a YouTube video link is rejected with a 400 error.
Check the list before you write anything to your database. This continues the Python file:
off = get_page("e_04ZrNroTo")
print()
print(off["video_id"], "| comments_disabled:", off["comments_disabled"],
"| comments:", len(off["comments"]), "| next_cursor:", off["next_cursor"])
Printed from the saved answer for the comments-off video:
e_04ZrNroTo | comments_disabled: True | comments: 0 | next_cursor: None
And in Node?
Node 18 and later includes fetch, so there is nothing to install. This version asks for the newest comments on the same video, then repeats the comments-off check. Save it as comments.mjs so top-level await works:
const API_KEY = "sk_live_your_api_key";
const BASE = "https://apiserpent.com/api/social/youtube/comments";
async function getPage(video, { sort = "top", cursor } = {}) {
const params = new URLSearchParams({ video, sort });
if (cursor) params.set("cursor", cursor);
const res = await fetch(`${BASE}?${params}`, { headers: { "X-API-Key": API_KEY } });
if (res.ok === false) throw new Error(`HTTP ${res.status}`);
return res.json();
}
const page = await getPage("dQw4w9WgXcQ", { sort: "newest" });
if (!page.comments || page.comments.length === 0) {
console.log("No comments came back for this video");
} else {
console.log(`${page.video_id} | sort: ${page.sort} | total_comments: ${page.total_comments}`);
for (const c of page.comments.slice(0, 2)) {
console.log(`${c.published} | ${c.likes} likes | ${c.reply_count} replies | ${c.author}`);
console.log(` ${c.text}`);
}
}
const off = await getPage("e_04ZrNroTo");
console.log();
console.log(`${off.video_id} | comments_disabled: ${off.comments_disabled} | comments: ${off.comments.length} | next_cursor: ${off.next_cursor}`);
Printed output, again from the saved answers with only fetch swapped for the file:
dQw4w9WgXcQ | sort: newest | total_comments: 2462805
7 minutes ago | 0 likes | 0 replies | @viewer4
Playing this while I tidy my desk
31 minutes ago | 0 likes | 0 replies | @viewer5
A friend sent me this link and I am not even mad
e_04ZrNroTo | comments_disabled: true | comments: 0 | next_cursor: null
These two comments were posted 7 and 31 minutes before the call, so they have no likes yet: likes is 0, like_text is an empty string, and replies_cursor is null because there are no replies to fetch. Across the 20 newest comments in the saved answer, 18 had no likes and 2 had one. The last line is the comments-off check in Node, where the same answer prints true and null.
What does one comment look like?
Each comment has fourteen fields: comment_id, text, author, author_channel_id, published, is_edited, likes, like_text, reply_count, replies_cursor, is_pinned, is_hearted, is_creator and is_verified.
Two fields differ from the official route. published is relative text, such as "7 years ago", with no exact timestamp. likes is the number as shown, rounded above 999, so 128K arrives as 128000 beside like_text "128K". If you need an exact date or an exact count, that is a reason to use the Data API.
Should you use sort=top or sort=newest?
Use top for a quick look at what viewers see first, and newest when you need a walk you can run again. top is YouTube's own ranking, and it can change between calls. Google's API offers the same two choices as relevance and time.
Here is how much it can move. In a check I ran on 24 November 2026, the first page of two videos was fetched twice, 10 minutes apart. On one video 17 of the first 20 comments repeated and on the other 16. The second page was less stable, with 15 of 20 and 8 of 20 repeating.
Pass the cursor from the last page to continue; a new walk that starts over with top may come back in a different order. The saved answers from 29 November show the ranking is not simply by likes either: the second comment on page one has 73K likes and the first comment on page two has 85K.
With newest, fresh comments join the front of the list and older ones follow in order, so start each run from the first page and drop repeats by comment_id. This post gives no number for how deep a walk goes, so treat a missing next_cursor as the end and never assume you hold every comment.
How do you page through the comments?
Pass the next_cursor from one response as cursor on the next call, for the same video and sort. When it is null or missing, the pages have run out. This generator walks newest-first, skips repeats, and stops after a page limit you choose. It continues the Python file above and is example code, not run:
import time
def walk_newest(video, max_pages=5):
"""Yield comments newest first, one page per call, skipping repeats."""
seen, cursor = set(), None
for _ in range(max_pages):
page = get_page(video, sort="newest", cursor=cursor)
for c in page.get("comments", []):
if c["comment_id"] not in seen:
seen.add(c["comment_id"])
yield c
cursor = page.get("next_cursor")
if not cursor:
break
time.sleep(0.5)
for comment in walk_newest("dQw4w9WgXcQ", max_pages=3):
print(comment["published"], comment["text"])
If a page holds 20 comments, as it did in every saved answer here, a thousand comments is 50 calls; a small video or the last page returns fewer. The same loop in Node is a while over getPage that feeds the cursor back in.
How do you get the replies to a comment?
Send a comment's replies_cursor to /api/social/youtube/comments/replies with the same video. A call returns one page of replies, and the size of a page varies, so do not plan around a fixed number. In the saved answers, the first call for a thread of 702 replies returned 9 and the second returned 45. An earlier check of mine on 24 November 2026 (12 first calls on six videos, two each) saw between 1 and 10 on a first call.
Follow next_cursor for the rest. This continues the Python file and walks two calls:
REPLIES = "https://apiserpent.com/api/social/youtube/comments/replies"
first = page["comments"][0]
cursor = first["replies_cursor"]
print()
print(f'{first["reply_count"]} replies under the first comment')
for call in (1, 2):
if not cursor:
break
r = requests.get(
REPLIES,
params={"video": page["video_id"], "cursor": cursor},
headers={"X-API-Key": API_KEY},
timeout=60,
)
r.raise_for_status()
replies = r.json()
got = replies["replies"]
if not got:
break
print(f'call {call}: {len(got)} replies, the first has {got[0]["like_text"]} likes | {got[0]["published"]} | {got[0]["author"]}')
cursor = replies.get("next_cursor")
print("more replies:", "yes" if cursor else "no")
Printed from the saved answers. After two calls there was still a next_cursor, so the thread had more to give:
702 replies under the first comment
call 1: 9 replies, the first has 6.5K likes | 7 years ago | @viewer24
call 2: 45 replies, the first has 34 likes | 6 years ago | @viewer32
more replies: yes
Those 54 replies are 7.7% of the 702. A reply has comment_id, text, author, author_channel_id, published, is_edited, likes, like_text and the three flags. On the official route the matching call is comments.list with parentId.
How do the two routes line up?
| YouTube Data API v3 | One call to the comments API | |
|---|---|---|
| What you need | Google Cloud project, API key | One key in an X-API-Key header |
| Comments per call | 1 to 100, default 20 | A page of top-level comments; 20 in each saved answer |
| Limit | 1 quota unit per call, 10,000 units a day by default | See the pricing page; 10 free calls to try |
| Order |
order=time or order=relevance
|
sort=newest or sort=top
|
| Next page |
pageToken from nextPageToken
|
cursor from next_cursor
|
| Date and likes | Exact date-time, exact count | "7 years ago", likes as shown |
| Replies | A limited number inline, then comments.list with parentId
|
One page per call from the replies endpoint; the size varies (9, then 45, in the saved answers) |
| Comments off, video removed or id not found | 403 commentsDisabled error when comments are off |
A normal response with an empty comments list; comments_disabled is true when comments are off |
Which route should you pick?
- A class project or a script you run yourself, on a few videos: the Data API. It is free and the quota is generous for that size.
-
A dashboard, a scheduled job or a feature in your product, where you want one key and no Google project: one call to a comments API, with
sort=newest, a page limit and a de-duplicating loop. - You want to analyse what viewers say in aggregate: see YouTube comments for sentiment analysis.
- Transcripts, search or channel data too: the YouTube Comments API page lists what sits under the same key, and getting transcripts in Python and Node covers the video's own words.
You can try a video in the playground on the Serpent site before writing code.
How I checked this, and what I could not verify
The Serpent snippets were run against the saved answers on Python 3.15.2 and Node 26.5.0. Only the network call was replaced by the saved file, so the printed output is what the snippets produced from answers my API returned on 29 November 2026. Handles were replaced by placeholders, channel ids by UC..., comment ids by invented ones, cursors by a fixed string, and the text of every comment and reply by invented text. The two sort=top pages are trimmed to 2 and 1 of the 20 comments each call returned; the newest page and both replies pages are complete. I read the quota, commentThreads.list, commentThreads, comments, comments.list and getting-started pages on 24 November 2026. Their footers show last-updated dates of 12 and 16 November 2026.
- The official-route code is example code. I did not run it, because it needs a Google key and this post made no call to Google's API.
- The Google pages I read do not say in so many words that an API key alone is enough for comments. Check the current authorisation rules before you build.
- I did not read the YouTube API Services terms or the process for asking for more quota. Read both before building a product on the Data API.
- The top-order stability figures (17 and 16 of 20 on page one, 15 and 8 of 20 on page two) come from a check on 24 November 2026 that I did not repeat on 29 November. It covered
toponly; how stablenewestis between runs was not measured. - The saved answers hold one thread of replies, one comments-off video, one removed video and one id that does not exist. Reply page sizes of 9 and 45 describe that thread, not every thread.
- How deep the cursor goes is not given here.
Originally published on apiserpent.com. The original also has the field-by-field figure and a longer FAQ. See also sentiment analysis on YouTube comments and the YouTube Comments API page.
Top comments (0)