ytranscript-api

Official JavaScript/TypeScript client for the yTranscript API — reliable YouTube transcript extraction without proxy management or player-response scraping.
- Your servers never touch YouTube — bot detection becomes our problem, not yours. Multi-strategy extraction (edge → direct → residential → Whisper) maximizes success, and failed requests are never charged.
- Captionless videos work — automatic Whisper speech-to-text fallback, one endpoint for every video.
- Simple and typed — one method, structured segments, zero runtime dependencies, CJS + ESM + types.
Works in Node.js ≥ 18, Bun, Deno, and edge runtimes (anything with fetch).
Install
npm install ytranscript-api
Quickstart
import { YTranscript } from "ytranscript-api";
const yt = new YTranscript("yk_live_...");
const t = await yt.transcript("dQw4w9WgXcQ");
console.log(t.lang);
console.log(t.segments[0]);
console.log(t.text);
console.log(t.whisper);
console.log(yt.lastQuota);
API
new YTranscript(apiKey, options?)
baseUrl | string | https://ytranscript.com/api/v1 | Override the API base URL (rarely needed) |
timeoutMs | number | 120000 | Request timeout — Whisper fallbacks on long videos take time |
yt.transcript(videoIdOrUrl, options?)
Accepts an 11-character video ID or any YouTube URL (youtube.com/watch, youtu.be/…, shorts, embeds).
lang | string | Preferred language code (e.g. "en", "es"). Defaults to the video's source language. |
Returns a Transcript:
interface Transcript {
videoId: string;
lang: string;
whisper: boolean;
cached: boolean;
unitsCharged: number;
segments: { text: string; offset: number; duration: number }[];
text: string;
}
yt.lastQuota
Quota headers from the most recent successful request: { limit, used, rateLimitRemaining }.
Error handling
Every failure throws a typed YTranscriptError:
import { YTranscript, YTranscriptError } from "ytranscript-api";
try {
await yt.transcript(videoId);
} catch (err) {
if (err instanceof YTranscriptError) {
switch (err.code) {
case "no_transcript":
case "quota_exceeded":
case "rate_limited":
case "unauthorized":
case "fetch_failed":
case "network_error":
}
console.error(err.status, err.message);
}
}
Units & pricing
Caption transcripts cost 1 unit; Whisper transcriptions (captionless videos) cost 15 units. Failed requests cost nothing. Plans start at $29/mo for 10,000 units — get an API key at ytranscript.com/developers.
Why not scrape it yourself?
You can — until you deploy. YouTube aggressively bot-detects transcript extraction from datacenter IPs (AWS, GCP, Vercel, Railway…), so DIY libraries tend to work locally and fail in production. This API exists so that arms race is our full-time job instead of your on-call incident. Extraction success rates are high but not absolute, which is exactly why failed requests are never charged.
License
MIT