Code Examples

Complete code examples using the official SDKs and cURL for all API endpoints.

PythonPyPI
pip install fetchtranscript
TypeScriptnpm
npm install fetchtranscript

Get Transcript

Fetch a transcript for a YouTube video with optional language and format parameters.

# Get transcript in JSON format (default)
curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ" \
  -H "Authorization: Bearer yt_your_api_key"

# Get transcript in plain text
curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?format=text" \
  -H "Authorization: Bearer yt_your_api_key"

# Get transcript in SRT format
curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?format=srt" \
  -H "Authorization: Bearer yt_your_api_key"

# Get Spanish transcript
curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?lang=es" \
  -H "Authorization: Bearer yt_your_api_key"
Example Response
{
  "video_id": "dQw4w9WgXcQ",
  "language": "en",
  "segments": [
    {
      "text": "We're no strangers to love",
      "start": 0.0,
      "duration": 2.5
    },
    {
      "text": "You know the rules and so do I",
      "start": 2.5,
      "duration": 3.1
    }
  ],
  "is_generated": false,
  "metadata": {
    "title": "Rick Astley - Never Gonna Give You Up",
    "author": "Rick Astley",
    "view_count": 1400000000
  }
}

List Available Languages

Get all available transcript languages for a video.

curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ/languages" \
  -H "Authorization: Bearer yt_your_api_key"
Example Response
{
  "video_id": "dQw4w9WgXcQ",
  "languages": [
    {
      "language_code": "en",
      "language": "English",
      "is_generated": false,
      "is_translatable": true
    },
    {
      "language_code": "es",
      "language": "Spanish",
      "is_generated": true,
      "is_translatable": true
    }
  ]
}

Get Video Metadata

Fetch metadata for a YouTube video.

curl -X GET "https://api.fetchtranscript.com/v1/videos/dQw4w9WgXcQ" \
  -H "Authorization: Bearer yt_your_api_key"
Example Response
{
  "video_id": "dQw4w9WgXcQ",
  "title": "Rick Astley - Never Gonna Give You Up",
  "channel_id": "UCuAXFkgsw1L7xaCfnd5JJOw",
  "channel_name": "Rick Astley",
  "duration": 212,
  "view_count": 1400000000,
  "like_count": 15000000,
  "upload_date": "20091025",
  "thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg"
}

Get Video Comments

Fetch comments for a YouTube video with pagination.

# Get first 100 comments (default)
curl -X GET "https://api.fetchtranscript.com/v1/videos/dQw4w9WgXcQ/comments" \
  -H "Authorization: Bearer yt_your_api_key"

# Get 50 comments
curl -X GET "https://api.fetchtranscript.com/v1/videos/dQw4w9WgXcQ/comments?limit=50" \
  -H "Authorization: Bearer yt_your_api_key"
Example Response
{
  "video_id": "dQw4w9WgXcQ",
  "comments": [
    {
      "comment_id": "abc123",
      "text": "This song never gets old!",
      "author": "John Doe",
      "like_count": 1520,
      "reply_count": 12,
      "published_at": "2023-06-15T10:30:00Z"
    }
  ],
  "total_count": 2500000,
  "has_more": true
}

List Channel Videos

Get videos from a YouTube channel with pagination.

# Using @handle
curl -X GET "https://api.fetchtranscript.com/v1/channels/@mkbhd/videos" \
  -H "Authorization: Bearer yt_your_api_key"

# Using channel ID with pagination
curl -X GET "https://api.fetchtranscript.com/v1/channels/UCBcRF18a7Qf58cCRy5xuWwQ/videos?limit=10&offset=0" \
  -H "Authorization: Bearer yt_your_api_key"

# Include Shorts
curl -X GET "https://api.fetchtranscript.com/v1/channels/@mkbhd/videos?include_shorts=true" \
  -H "Authorization: Bearer yt_your_api_key"
Example Response
{
  "channel_id": "UCBcRF18a7Qf58cCRy5xuWwQ",
  "videos": [
    {
      "video_id": "abc123xyz",
      "title": "Galaxy S25 Ultra Review",
      "duration": 945,
      "view_count": 4200000,
      "thumbnail_url": "https://i.ytimg.com/vi/abc123xyz/maxresdefault.jpg"
    }
  ],
  "total_count": 1500,
  "has_more": true
}

Search Videos

Search YouTube videos by query.

curl -X GET "https://api.fetchtranscript.com/v1/search?q=machine%20learning&limit=20" \
  -H "Authorization: Bearer yt_your_api_key"
Example Response
{
  "query": "machine learning tutorial",
  "results": [
    {
      "video_id": "dQw4w9WgXcQ",
      "title": "Machine Learning in 10 Minutes",
      "channel_name": "TechChannel",
      "duration": 612,
      "view_count": 2500000,
      "thumbnail_url": "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg"
    }
  ],
  "total_results": 20
}

Complete Example: Batch Processing

Fetch transcripts for all videos from a channel using the SDK.

import time
from fetchtranscript import FetchTranscriptClient, VideoNotFoundError

client = FetchTranscriptClient(api_key="yt_your_api_key")

# Get all videos from a channel
all_videos = client.channels.get_all_videos("@mkbhd")
print(f"Found {len(all_videos)} videos")

transcripts = []
for i, video in enumerate(all_videos):
    print(f"Processing {i+1}/{len(all_videos)}: {video['title'][:50]}...")

    try:
        transcript = client.transcripts.get(video["video_id"])
        transcripts.append({
            "video_id": video["video_id"],
            "title": video["title"],
            "transcript": transcript["text"]
        })
    except VideoNotFoundError:
        pass  # No transcript available

    time.sleep(0.3)  # Respect rate limits

print(f"Successfully fetched {len(transcripts)} transcripts")
print(f"Credits remaining: {client.credits_remaining}")

Next Steps