@fetchlayer/youtube
v0.2.0
Published
Official FetchLayer SDK for YouTube data. Scrape YouTube comments, reply threads, and transcripts from any video with JavaScript and TypeScript.
Maintainers
Readme
YouTube Comments Scraper & API Client for JavaScript / TypeScript
The official JavaScript & TypeScript SDK for the FetchLayer YouTube API.
Scrape YouTube comments. Pull reply threads. Extract video transcripts. 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.
Install
npm install @fetchlayer/youtubepnpm add @fetchlayer/youtubeyarn add @fetchlayer/youtubeGet your API key
- 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.
Quick start
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",
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.
Why use this instead of scraping YouTube yourself
| 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, replies, AND transcripts | Three endpoints, one SDK |
All methods
const youtube = new FetchLayerYoutube({ apiKey });| Method | What it does |
| --- | --- |
| youtube.getComments(params) | Scrape top-level comments from a video |
| youtube.getCommentReplies(params) | Fetch replies to a specific comment |
| youtube.getTranscript(params) | Extract video transcript with timestamps |
Examples
Scrape top comments from a video
const response = await youtube.getComments({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
sort: "top", // "top" (most liked) or "newest"
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}`);
}Get the latest discussion
const response = await youtube.getComments({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
sort: "newest",
pages: 5,
});Fetch replies to a specific comment
const thread = await youtube.getCommentReplies({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
commentId: "Ugz...",
depth: 2,
});
console.log(thread.comment);
for (const reply of thread.nestedReplies ?? []) {
console.log(` ↳ @${reply.username}: ${reply.comment}`);
}Extract a video transcript
const transcript = await youtube.getTranscript({
videoUrl: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
language: "en",
});
console.log(transcript.text);
for (const segment of transcript.segments ?? []) {
console.log(`[${segment.start}s] ${segment.text}`);
}Error handling
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
}
}Configuration
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+)
});What this package is
- 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
How it works
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.
Pricing
| | | | --- | --- | | 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 →
Use cases
- 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
Links
| | | | --- | --- | | Get API key | fetchlayer.dev/signin | | Product page | fetchlayer.dev/youtube-comments-api | | Homepage | fetchlayer.dev | | npm | @fetchlayer/youtube | | Issues | GitHub Issues |
License
MIT — see LICENSE.
