YTAPI.devDocs

SDKs

Official Python and JavaScript/TypeScript clients for YTAPI, with typed errors, retries and pagination.

YTAPI has official clients for Python and for JavaScript/TypeScript. Both are open source under the MIT license and have no runtime dependencies. They wrap the same HTTP API documented here, so anything you can do with curl you can do with them.

PythonJavaScript / TypeScript
Packageytapi-sdk on PyPI@ytapi/sdk on npm
Installpip install ytapi-sdknpm install @ytapi/sdk
Importfrom ytapi import YTAPIimport { YTAPI } from "@ytapi/sdk"
RuntimePython 3.10+Node 18+, plus Bun, Deno and Cloudflare Workers; ESM and CommonJS
Sourcegithub.com/ytapi/ytapi-pythongithub.com/ytapi/ytapi-js

Quickstart

Create a key in the Developer Dashboard and set it as YTAPI_API_KEY. Both clients read it from the environment, or you can pass it in.

from ytapi import YTAPI

api = YTAPI()  # or YTAPI(api_key="sk_...")

transcript = api.get_transcript("dQw4w9WgXcQ")
for segment in transcript["segments"][:3]:
    print(segment["start"], segment["text"])

# Text formats (markdown, text, srt, vtt) come back as a string.
print(api.get_transcript("dQw4w9WgXcQ", format="markdown"))
import { YTAPI } from "@ytapi/sdk";

const api = new YTAPI(); // or new YTAPI({ apiKey: "sk_..." })

const transcript = await api.getTranscript("dQw4w9WgXcQ");
if (typeof transcript !== "string") {
  for (const segment of transcript.segments?.slice(0, 3) ?? []) {
    console.log(segment.start, segment.text);
  }
}

// Text formats (markdown, text, srt, vtt) come back as a string.
console.log(await api.getTranscript("dQw4w9WgXcQ", { format: "markdown" }));

Server-side only

Use the JavaScript client from your server, a serverless function or a worker. An API key in browser code is visible to every visitor.

Methods

Each method maps to one endpoint and costs what that endpoint costs (see Credits).

PythonTypeScriptEndpoint
get_transcriptgetTranscriptPOST /v1/transcripts
get_basic_infogetBasicInfoGET /v1/videos/{id}/basic-info
get_video_infogetVideoInfoGET /v1/videos/{id}/video-info
get_playlist, iter_playlist_videosgetPlaylist, iterPlaylistVideosGET /v1/playlists/{id}
get_channelgetChannelGET /v1/channels/{id}
get_channel_latestgetChannelLatestGET /v1/channels/{id}/latest
list_channel_videos, iter_channel_videoslistChannelVideos, iterChannelVideosGET /v1/channels/{id}/videos
list_channel_playlists, iter_channel_playlistslistChannelPlaylists, iterChannelPlaylistsGET /v1/channels/{id}/playlists
search, iter_searchsearch, iterSearchGET /v1/search
get_suggestionsgetSuggestionsGET /v1/search/suggestions
create_batch, get_batch, poll_batchcreateBatch, getBatch, pollBatchPOST /v1/batch, GET /v1/batch/{id}

The iter_* / iter* methods follow next_cursor for you. Each page they fetch is one request and one credit, so stop iterating once you have what you need.

Errors

A non-2xx response raises (Python) or throws (TypeScript) a typed error that carries the status, the error code from the error envelope and, for 429s, retry_after / retryAfter.

StatusError class
401AuthError
402InsufficientCreditsError
404NotFoundError, for example captions_disabled or video_unavailable
429RateLimitedError: rate_limited or daily_limit_exceeded
5xxServerError
Network error or timeoutYTAPIError with status 0

All of them extend YTAPIError.

Retries

By default the clients retry a 429, a 5xx or a network error twice, backing off from 0.5 seconds up to 8 seconds and honoring Retry-After. They do not retry:

  • A 429 that asks for a wait longer than 60 seconds, such as the free tier's daily limit, which resets at 00:00 UTC. The error is raised at once so your program doesn't hang. Change the cutoff with max_retry_wait (Python, seconds) or maxRetryWaitMs (TypeScript).
  • Creating a batch after a 5xx or a network error, because the job may already exist.

Set max_retries=0 / maxRetries: 0 to turn retries off.

Other languages

For Go, Ruby, PHP or anything else, call the API over HTTPS as shown in the Quickstart. The OpenAPI spec lists the endpoints and schemas.

On this page