Skip to content

YouTube Transcript API with cURL

This page shows how to get a YouTube transcript from the command line with cURL and TranscriptAPI. It’s the quickest way to test your API key and see the response before you write code.

Writing code? See the Python and JavaScript / Node.js quick starts.

  • An API key. Sign up to get 100 free credits (no card required), then copy a key from the API Keys dashboard.

  • cURL in a bash-compatible shell (macOS, Linux, WSL, or Git Bash on Windows). Run curl --version to check it is installed.

  • Your key in an environment variable, so it stays out of your shell history:

    Terminal window
    export TRANSCRIPT_API_KEY="your_api_key"

Each successful transcript request costs 1 credit. Failed requests (4xx and 5xx) cost nothing. See Credit Usage & Billing.

Terminal window
curl -G "https://transcriptapi.com/api/v2/youtube/transcript" \
--data-urlencode "video_url=https://www.youtube.com/watch?v=dQw4w9WgXcQ" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"

-G sends the parameters as a query string, and --data-urlencode encodes the video URL for you. video_url also accepts a short URL (https://youtu.be/...) or the 11-character video ID.

Response (shortened):

{
"video_id": "dQw4w9WgXcQ",
"language": "en",
"transcript": [
{ "text": "[♪♪♪]", "start": 1.36, "duration": 1.68 },
{ "text": "♪ We're no strangers to love ♪", "start": 18.64, "duration": 3.24 },
{ "text": "♪ You know the rules\nand so do I ♪", "start": 22.64, "duration": 4.32 }
],
"length_seconds": 213,
"lengthText": "3:33"
}

Each segment has the caption text, its start time in seconds, and its duration in seconds. The full field list is in the API Reference.

Not every video has a transcript. Before you spend a credit, ask /youtube/info. It takes the same video_url as the transcript endpoint. The API Reference says “no credit is consumed” and “The same API key and active plan are required as for the transcript endpoint.”

Terminal window
curl -s -G "https://transcriptapi.com/api/v2/youtube/info" \
--data-urlencode "video_url=dQw4w9WgXcQ" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY" \
-w "\n%{http_code}\n"

A 200 gives you the video’s metadata (title, author_name, author_url, thumbnail_url) and available_languages, a list of code, name, and kind entries. Then fetch the transcript with the request from Get a transcript. A 404 means the video does not exist or has no captions, so there is nothing to fetch.

This is also a free way to test your API key.

Set format to text and include_timestamp to false to get the whole transcript as one string in the transcript field. Write the response to a file with -o:

Terminal window
curl -G "https://transcriptapi.com/api/v2/youtube/transcript" \
--data-urlencode "video_url=dQw4w9WgXcQ" \
-d format=text \
-d include_timestamp=false \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY" \
-o dQw4w9WgXcQ.json

Add -d send_metadata=true to include the video title, channel name, channel URL, and thumbnail.

The available_languages list from the free check above shows the languages a video offers. Pass a comma-separated priority list in language. The API returns the first one that exists, and the language field in the response tells you which one you got. Codes starting with asr are YouTube’s auto-generated captions.

Terminal window
curl -G "https://transcriptapi.com/api/v2/youtube/transcript" \
--data-urlencode "video_url=dQw4w9WgXcQ" \
--data-urlencode "language=de,en" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"

Add -w "\n%{http_code}\n" to print the HTTP status after the response body:

Terminal window
curl -s -G "https://transcriptapi.com/api/v2/youtube/transcript" \
--data-urlencode "video_url=dQw4w9WgXcQ" \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY" \
-w "\n%{http_code}\n"

A 200 means the transcript came back and 1 credit was used. Any other status means the request failed and no credit was used.

Every error response has a detail field. These are the ones you are most likely to meet.

401 Unauthorized. The API key is missing or wrong. The response has a WWW-Authenticate: Bearer header and a short message:

{ "detail": "Invalid API key" }

Check that TRANSCRIPT_API_KEY is set in the current shell (echo ${#TRANSCRIPT_API_KEY} prints its length, not the key), and that the key still exists in the API Keys dashboard. Don’t retry until you fix the key.

402 Payment Required. You have run out of credits, or you have no active plan. Here detail is an object with a reason and a link to fix it:

{
"detail": {
"message": "You have an active plan, but you've run out of credits.",
"reason": "insufficient_credits",
"action_label": "Top up credits",
"action_url": "https://transcriptapi.com/top-up"
}
}

When reason is no_active_paid_plan, action_url points to Billing instead. Free endpoints such as /youtube/info also need an active plan, so they can return 402 too. Open action_url, then send the request again.

404 Not Found. There is no transcript to return. The code field tells you why:

{
"detail": "No transcript available for video tfLTHCpPsSY",
"code": "no_captions"
}

Other codes are video_unavailable, age_restricted, live_not_started, and no_transcript_for_requested_languages. The last one comes with an available_languages list you can retry with. Don’t retry the same request, except live_not_started after the stream has aired. Each code is explained in 404 error codes.

429 Too Many Requests. You went over your plan’s rate limit, which all API keys on your account share. Wait the number of seconds in the Retry-After header, then retry. Rate-limited requests cost no credits.

You might also see 422 when video_url is not a valid URL or video ID (fix the input), or 408 and 503 for a temporary failure (retry after a few seconds).

The full error list and response bodies are in Error Handling.

The same key works for the other endpoints. For example, a YouTube search (1 credit per page):

Terminal window
curl -G "https://transcriptapi.com/api/v2/youtube/search" \
--data-urlencode "q=machine learning explained" \
-d type=video \
-H "Authorization: Bearer $TRANSCRIPT_API_KEY"

See the API Reference for channel, playlist, and video metadata endpoints.

  • API Reference: every endpoint, parameter, and response field
  • MCP server: use the same account from Claude, ChatGPT, and other AI assistants
  • Swagger UI: try requests in your browser