# YouTube Transcript API (youtube-transcript.ai)

You are helping a user fetch YouTube video transcripts through this HTTP API. Ask what they are building (a script, an n8n or Make workflow, an agent tool) and write that for them. If they have not given you an API key, ask for it. Never invent one.

## Request

    GET https://youtube-transcript.ai/transcript/{VIDEO_ID}.txt

- `{VIDEO_ID}` is the 11-character ID from a YouTube link: the value after `v=` in `youtube.com/watch?v=...`, or the last path segment of `youtu.be/...`, `/shorts/...` and `/embed/...`.
- Authentication is required. Use one of:
  - header `Authorization: Bearer {API_KEY}`
  - header `X-API-Key: {API_KEY}`
  - query string `?key={API_KEY}`, for tools that only accept a URL
- Optional query parameter `lang`: a caption language code such as `en`, `es`, `ja` or `zh-Hant`. Without it the API returns the default track, human-written captions before auto-generated ones.

## Response

- Status `200`, `Content-Type: text/markdown; charset=utf-8`. It is text, not JSON.
- A short header comes first: title, source URL, language, duration, word count and the other caption languages available. The transcript follows in short paragraphs, each starting with a `[m:ss]` or `[h:mm:ss]` timestamp.
- `X-RateLimit-Limit` and `X-RateLimit-Remaining` report the quota left today.
- A `200` whose body starts with `# No captions available` means the video has no captions. There is nothing to retry.

## Errors

- `401`: the key is missing or not recognised. Ask the user to check it or create a new one.
- `429`: the daily quota is used up. `Retry-After` gives the seconds until it resets at 00:00 UTC. Do not retry before then.
- `5xx` with a body starting `# Transcript unavailable`: a temporary failure fetching from YouTube. Retry once after a few seconds.

## Limits

- Free key: 10 requests a day. Pro: 1,000 a day for $120 a year, on the same key.
- Every request counts as one, including repeats of the same video. Store transcripts you have already fetched instead of requesting them again.

## Getting a key

The user creates a key at https://youtube-transcript.ai/get-api-key with a Google sign-in. It takes about a minute. Upgrading to Pro happens on the same page.

## Examples

cURL:

    curl -H "Authorization: Bearer $YT_TRANSCRIPT_KEY" \
      "https://youtube-transcript.ai/transcript/dQw4w9WgXcQ.txt?lang=en"

Python:

    import os, requests

    def get_transcript(video_id, lang=None):
        r = requests.get(
            f"https://youtube-transcript.ai/transcript/{video_id}.txt",
            headers={"Authorization": f"Bearer {os.environ['YT_TRANSCRIPT_KEY']}"},
            params={"lang": lang} if lang else None,
            timeout=60,
        )
        r.raise_for_status()
        return r.text

JavaScript:

    async function getTranscript(videoId, lang) {
      const url = new URL(`https://youtube-transcript.ai/transcript/${videoId}.txt`)
      if (lang) url.searchParams.set("lang", lang)
      const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.YT_TRANSCRIPT_KEY}` } })
      if (!res.ok) throw new Error(`Transcript request failed: ${res.status}`)
      return res.text()
    }

## Other ways to use it

- In Claude or ChatGPT without code: connect the MCP server at https://youtube-transcript.ai/mcp?key={API_KEY}. It exposes one tool, `get_youtube_transcript`. Setup notes for agents: https://youtube-transcript.ai/mcp.md
- To read one video by hand, with no key: https://youtube-transcript.ai/?v={VIDEO_ID}
- Full reference: https://youtube-transcript.ai/youtube-transcript-api
