The official JavaScript & TypeScript SDK for the FetchLayer YouTube Comments API.
Scrape YouTube comments. Pull nested replies. Get likes, authors, and dates. All as clean JSON from a single API — no Google Cloud project, no OAuth, no HTML parsing.
Open-source SDK, hosted API. This package is MIT-licensed. The API requires a free FetchLayer API key — no subscriptions, no contracts, no lock-in. Pay only for what you use.
npm install @fetchlayer/youtubepnpm add @fetchlayer/youtubeyarn add @fetchlayer/youtube- Go to fetchlayer.dev
- Sign in with your email
- Copy your API key from the dashboard
That's it. No credit card. No trial expiration. You get free requests to start, then pay-as-you-go when you need more.
import { FetchLayerYoutube } from "@fetchlayer/youtube";
const youtube = new FetchLayerYoutube({
apiKey: process.env.FETCHLAYER_API_KEY!,
});
// Scrape comments from any YouTube video
const comments = await youtube.getComments({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
sort: "top",
depth: 1,
pages: 2,
});
console.log(comments);That's 4 lines to get structured YouTube comment data. No Google Cloud setup, no OAuth dance, no broken scrapers.
| Problem | FetchLayer |
|---|---|
| YouTube blocks your IP | We handle rotation and resilience |
| HTML structure changes break your parser | You get stable JSON |
| YouTube Data API needs a Google Cloud project + quota | Simple Bearer token, no quota |
| Maintaining scraping infra is a full-time job | npm install and done |
| You need comments AND nested replies | One endpoint, one SDK |
const youtube = new FetchLayerYoutube({ apiKey });| Method | What it does |
|---|---|
youtube.getComments(params) |
Scrape comments and nested replies from a video |
const response = await youtube.getComments({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
sort: "top", // "top" (most liked) or "newest"
depth: 1, // include one level of replies
pages: 3, // scroll for more comments
});
for (const comment of response.comments ?? []) {
console.log(`${comment.username}: ${comment.comment}`);
console.log(` ${comment.likes} likes · ${comment.date}`);
}const response = await youtube.getComments({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
sort: "newest",
pages: 5,
});const response = await youtube.getComments({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
depth: 2,
});
for (const comment of response.comments ?? []) {
console.log(`@${comment.username}: ${comment.comment}`);
for (const reply of comment.nestedReplies ?? []) {
console.log(` ↳ @${reply.username}: ${reply.comment}`);
}
}import { FetchLayerYoutube, FetchLayerError } from "@fetchlayer/youtube";
try {
const comments = await youtube.getComments({ videoUrl: "https://..." });
} catch (err) {
if (err instanceof FetchLayerError) {
console.error(err.status); // 401, 429, etc.
console.error(err.message); // Human-readable error from the API
}
}const youtube = new FetchLayerYoutube({
apiKey: "your-key", // Required
baseUrl: "...", // Default: https://api.fetchlayer.dev/youtube
timeoutMs: 120000, // Default: 120s
fetch: customFetch, // Default: global fetch (Node 18+)
});- Zero dependencies — uses native
fetch, nothing else - Dual build — ESM + CommonJS, works everywhere
- Fully typed — TypeScript declarations included
- Tiny — under 6 KB bundled
- Open source — MIT license, contributions welcome
You call FetchLayer → FetchLayer returns structured YouTube comment data as JSON → you use it however you want.
No YouTube account needed. No Google Cloud project. No scraping infrastructure on your end.
| Free tier | Included with every account — start building immediately |
| Pay-as-you-go | $1.99 per 1,000 requests. Credits never expire. |
| Subscriptions | Available for heavy use — predictable pricing at scale |
| Rate limits | None |
No credit card required to start. No monthly commitment. No overages. Get your API key →
- Audience research — find what viewers ask, praise, and complain about in the comments
- Content research — discover recurring questions and content requests for your next video
- Competitive intelligence — monitor comments on competitor videos and launches
- Sentiment analysis — pull comments and run NLP on real viewer opinions
- Community management — track feedback and engagement across your channel
- AI agents — give your LLM real-time YouTube context via FetchLayer's MCP server
| Get API key | fetchlayer.dev/signin |
| Product page | fetchlayer.dev/youtube-comments-api |
| Homepage | fetchlayer.dev |
| npm | @fetchlayer/youtube |
| Issues | GitHub Issues |
MIT — see LICENSE.