Tutorial
How to Get YouTube Comments Through an API
Extract public YouTube comments as structured JSON for audience research, monitoring, and AI analysis. Use the replies endpoint for comment threads.
Written by Alex P.
- youtube comments API
- youtube comment scraper
- youtube replies API
- audience research
- youtube comment analysis
YouTube comments are often the most specific audience feedback attached to a video. They contain questions, objections, requests for follow-up content, product reactions, and conversations between viewers. An API workflow lets you collect that feedback without manually copying it from the page.
This guide shows how to retrieve public YouTube comments as structured JSON with FetchLayer. Use the separate /comments/replies endpoint to load reply threads for specific comments.
Start with the YouTube Comments API or see the existing YouTube API reference.
If you work in JavaScript or TypeScript, you can skip the raw fetch wrapper and install the official package: @fetchlayer/youtube. The SDK is open source on GitHub and includes typed responses for all endpoints.
What the endpoint returns
The FetchLayer endpoint accepts a public YouTube video URL. It returns comment data including:
- Author username
- Full comment text
- Like count
- Relative date shown by YouTube
- Whether the comment has replies (use the
/comments/repliesendpoint to load them)
You can set whether to retrieve top or newest comments, a maximum limit, and how many pages to scroll for more comments.
1. Send a video URL
Make a POST request to the YouTube comments endpoint:
curl -X POST https://api.fetchlayer.dev/youtube/comments \
-H "Authorization: Bearer ss-your-key" \
-H "Content-Type: application/json" \
-d '{
"videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"sort": "newest",
"pages": 2
}'
Use newest for a fresh snapshot of a launch, event, or published video. Use top when you want the comments that have attracted the most engagement.
2. Work with the structured response
The response is an array of top-level comments. Each comment includes a hasReplies flag. Use the /comments/replies endpoint to load a specific comment thread:
[
{
"username": "@viewer",
"comment": "Please cover offline mode next.",
"likes": 42,
"hasReplies": true,
"date": "1 day ago"
}
]
To get the replies for a comment, call the replies endpoint:
curl -X POST https://api.fetchlayer.dev/youtube/comments/replies \
-H "Authorization: Bearer ss-your-key" \
-H "Content-Type: application/json" \
-d '{
"videoUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"commentId": "Ugz...",
"depth": 1
}'
3. Fetch comments in JavaScript
const response = await fetch('https://api.fetchlayer.dev/youtube/comments', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.FETCHLAYER_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
sort: 'top',
pages: 1,
}),
});
if (!response.ok) throw new Error(`FetchLayer returned ${response.status}`);
const comments = await response.json();
console.log(comments);
Keep the API key on the server. A cron job, serverless function, worker, or backend service is the right place to retrieve and store comments.
4. Choose the right collection strategy
There is no universal “best” comment set. Choose based on the question:
| Question | Suggested settings |
|---|---|
| How did viewers react to a newly published video? | sort: newest |
| Which feedback is most visible to the community? | sort: top |
| Are the useful insights in comment threads? | Use /comments/replies with depth |
| Do I need a broader snapshot? | Increase pages carefully |
For a repeatable research workflow, record the source video URL, retrieval time, request settings, and the full comments returned. That context makes later analysis more trustworthy.
5. Analyze comments with an AI agent
The strongest AI workflows ask a precise question and preserve source evidence.
For example:
Read these comments. Group them into praise, confusion, objections, and requests for future content. Cite the most representative comments for each theme.
This can reveal a missing tutorial, an unclear claim, a product objection, or a topic that deserves a follow-up video. Avoid relying on a sentiment score alone; an agent should retain the original comments that support each conclusion.
For detailed workflow ideas, see how to analyze YouTube comments and YouTube audience research from comments.
For a no-code route, FetchLayer Research Chat can retrieve the public comments, analyze the discussion, and create a downloadable CSV or JSON artifact from a plain-English request. Read the full guide to exporting YouTube comments to CSV.
If Claude, Codex, Hermes, or another MCP-compatible AI client is already where you work, connect it to FetchLayer instead. Your own agent can retrieve the comments and replies, preserve the evidence, and create the report or file in your existing workflow. Set up FetchLayer MCP.
Official YouTube API versus FetchLayer
Google’s YouTube Data API is valuable when you need the broader official API surface. It requires a Google project, API enablement, and quota management. FetchLayer is focused on the public comment-retrieval path: send a public video URL, authenticate with one FetchLayer key, and receive structured comment data.
Use whichever approach fits the job. For simple public comment collection feeding research, monitoring, or AI workflows, FetchLayer removes the project setup and retrieval plumbing.