POST
/
api
/
youtube-transcribe
curl --request POST \
  --url https://nano-gpt.com/api/api/youtube-transcribe \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "urls": [
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    "https://youtu.be/kJQP7kiw5Fk"
  ]
}'
{
  "transcripts": [
    {
      "url": "<string>",
      "success": true,
      "title": "<string>",
      "transcript": "<string>",
      "error": "<string>"
    }
  ],
  "summary": {
    "requested": 123,
    "processed": 123,
    "successful": 123,
    "failed": 123,
    "totalCost": 123
  }
}

Overview

The YouTube Transcription API allows you to extract transcripts from YouTube videos programmatically. This is useful for content analysis, accessibility, research, or any application that needs to work with YouTube video content in text format.

Authentication

The API supports two authentication methods:

Include your API key in the request headers:

x-api-key: YOUR_API_KEY

2. Session Authentication

If you’re making requests from a browser with an active session, authentication will be handled automatically via cookies.

Request Format

Headers

{
  "Content-Type": "application/json",
  "x-api-key": "YOUR_API_KEY"
}

Body

{
  "urls": [
    "https://www.youtube.com/watch?v=VIDEO_ID_1",
    "https://youtu.be/VIDEO_ID_2",
    "https://youtube.com/watch?v=VIDEO_ID_3"
  ]
}

Parameters

ParameterTypeRequiredDescription
urlsstring[]YesArray of YouTube URLs to transcribe. Maximum 10 URLs per request.

Supported YouTube URL Formats

  • https://www.youtube.com/watch?v=VIDEO_ID
  • https://youtu.be/VIDEO_ID
  • https://youtube.com/embed/VIDEO_ID
  • https://m.youtube.com/watch?v=VIDEO_ID
  • https://youtube.com/live/VIDEO_ID

Response Format

Success Response (200 OK)

{
  "transcripts": [
    {
      "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
      "success": true,
      "title": "Rick Astley - Never Gonna Give You Up",
      "transcript": "We're no strangers to love\nYou know the rules and so do I..."
    },
    {
      "url": "https://youtube.com/watch?v=invalid",
      "success": false,
      "error": "Video not found or transcripts not available"
    }
  ],
  "summary": {
    "requested": 2,
    "processed": 2,
    "successful": 1,
    "failed": 1,
    "totalCost": 0.01
  }
}

Response Fields

transcripts Array

Each transcript object contains:

  • url (string): The original YouTube URL
  • success (boolean): Whether the transcript was successfully retrieved
  • title (string, optional): Video title (only if successful)
  • transcript (string, optional): The full transcript text (only if successful)
  • error (string, optional): Error message (only if failed)

summary Object

  • requested: Number of URLs provided in the request
  • processed: Number of valid YouTube URLs found and processed
  • successful: Number of transcripts successfully retrieved
  • failed: Number of transcripts that failed
  • totalCost: Total cost in USD for successful transcripts

Error Responses

400 Bad Request

{
  "error": "Please provide an array of YouTube URLs"
}

401 Unauthorized

{
  "error": "Invalid session"
}

402 Payment Required

{
  "error": "Insufficient balance. Current balance: $0.50, required: $1.00"
}

429 Too Many Requests

{
  "error": "Rate limit exceeded. Please wait before sending another request."
}

Pricing

  • Cost: $0.01 USD per successful transcript
  • Billing: You are only charged for successfully retrieved transcripts
  • Failed transcripts: No charge

Rate Limits

  • 10 requests per minute per IP address
  • 10 URLs maximum per request

Code Examples

const axios = require('axios');

async function getYouTubeTranscripts() {
  try {
    const response = await axios.post('https://nano-gpt.com/api/youtube-transcribe', {
      urls: [
        'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
        'https://youtu.be/kJQP7kiw5Fk'
      ]
    }, {
      headers: {
        'Content-Type': 'application/json',
        'x-api-key': 'YOUR_API_KEY'
      }
    });

    console.log('Transcripts:', response.data.transcripts);
    console.log('Summary:', response.data.summary);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
}

Best Practices

  1. Batch Requests: Send multiple URLs in a single request (up to 10) rather than making individual requests for better efficiency.

  2. Error Handling: Always check the success field for each transcript, as some videos may not have transcripts available.

  3. Rate Limiting: Implement exponential backoff if you receive a 429 status code.

  4. URL Validation: The API automatically detects and validates YouTube URLs, but validating on your end can save API calls.

  5. Cost Monitoring: Use the summary.totalCost field to track your spending.

Limitations

  1. Transcript Availability: Not all YouTube videos have transcripts available. Videos may lack transcripts if:

    • The creator hasn’t enabled auto-captions
    • The video is private or age-restricted
    • The video has been deleted
    • The video is a live stream without captions
  2. Language: Transcripts are returned in their original language. The API doesn’t provide translation services.

  3. Formatting: Transcripts are returned as plain text with natural line breaks. Timestamp information is not included.

Use Cases

  • Content Analysis: Analyze video content for keywords, topics, or sentiment
  • Accessibility: Create accessible versions of video content
  • Research: Study communication patterns, language use, or content trends
  • SEO: Extract content for search engine optimization
  • Education: Create study materials from educational videos
  • Content Moderation: Check video content for compliance

Support

For technical support or questions about the YouTube Transcription API:

Authorizations

x-api-key
string
header
required

Body

application/json

YouTube transcription parameters

The body is of type object.

Response

200
application/json

YouTube transcription response with results for each URL

The response is of type object.