Skip to content

Repository files navigation

YouTube Transcript API: Node.js / TypeScript SDK

License Website TypeScript

The official Node.js / TypeScript SDK (getyoutubetranscript) for the GetYouTubeTranscript YouTube Transcript API. Get YouTube video transcripts in JavaScript without a Google API key, yt-dlp, or a headless browser, plus YouTube search, channel, and playlist data over a simple REST API.

  • Fully typed, Promise-based client
  • Zero dependencies - built on native fetch (Node 18+)
  • ESM and CommonJS builds, with .d.ts types included
  • Typed errors: every failed request throws a GetYouTubeTranscriptError with a code, message, and statusCode

Not yet published to npm. Install directly from GitHub:

npm install github:tubeagentkit/youtube-transcript-api-node

Quickstart

import { GetYouTubeTranscript } from "getyoutubetranscript";

const client = new GetYouTubeTranscript({ apiKey: process.env.GYT_API_KEY! });

const { title, transcript, word_count } = await client.getTranscript({
  v: "https://www.youtube.com/watch?v=jNQXAC9IVRw",
});

console.log(title, word_count, transcript.slice(0, 200));

Getting an API key

Every request needs an API key. New accounts get 100 free credits, no card required - grab one at getyoutubetranscript.com.

Prefer to do it in code? Use the self-serve signup flow, which sends a 6-digit email OTP and hands back a key once verified:

import { signup, verifySignup } from "getyoutubetranscript";

await signup("you@example.com");
// check your inbox for the 6-digit code, then:
const { api_key } = await verifySignup("you@example.com", "123456");

Usage

Every method returns the parsed data payload directly - no need to unwrap { success, data } yourself.

// Search videos or channels
const results = await client.search({ q: "lofi beats" });

// Resolve a channel handle to its channel ID (free)
const { channel_id } = await client.resolveChannel({ handle: "@mkbhd" });

// List a playlist's videos
const playlist = await client.getPlaylist({ list: "PLillGF-RfqbYE6Ik_EuXA2iZFcE082B3s" });

// Channel metadata + latest uploads (free)
const channel = await client.getChannelLatest({ channel: "@mkbhd" });

// Search within a channel
const channelResults = await client.searchChannel({ channel: "@mkbhd", q: "iphone" });

// List all of a channel's uploads
const uploads = await client.listChannelVideos({ channel: "@mkbhd" });

// Check remaining credits, plan, and rate limit (free)
const { plan_credits_left, plan } = await client.getCredits();

Paginated endpoints (search, getPlaylist, searchChannel, listChannelVideos) return a continuation token you feed back in on the next call:

let page = await client.search({ q: "lofi beats" });
while (page.pagination?.next_page_token) {
  page = await client.search({ pageToken: page.pagination.next_page_token });
}

Handling errors

import { GetYouTubeTranscriptError } from "getyoutubetranscript";

try {
  await client.getTranscript({ v: "invalid" });
} catch (err) {
  if (err instanceof GetYouTubeTranscriptError) {
    console.error(err.statusCode, err.code, err.message);
    // e.g. 402 PAYMENT_REQUIRED "You have used all your credits."
  } else {
    throw err;
  }
}

API coverage

Method Endpoint Credits
getTranscript(params) GET /transcript 1
search(params) GET /search 1
resolveChannel(params) GET /resolve free
getPlaylist(params) GET /playlist 1
getChannelLatest(params) GET /channel/latest free
searchChannel(params) GET /channel/search 1
listChannelVideos(params) GET /channel/videos 1
getCredits() GET /credits free
signup(email) POST /signup free
verifySignup(email, otp) POST /signup/verify free

Full parameter and response shapes are exported as TypeScript types (TranscriptData, SearchData, PlaylistData, etc.) - see src/types.ts or your editor's autocomplete.

Development

npm install
npm run build       # tsup -> dist/ (ESM + CJS + .d.ts)
npm test            # unit tests, mocked fetch, no network
npm run typecheck

Live integration tests hit the real API and are skipped unless GYT_API_KEY is set:

GYT_API_KEY=sk_live_... npm run test:live

Links

Related projects

Other ways to use the GetYouTubeTranscript API:

License

MIT © tubeagentkit

About

YouTube Transcript API Node.js / TypeScript SDK: get YouTube video transcripts, search YouTube, list channel and playlist videos. Typed, zero dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages