API Documentation

YouTube Video Analysis API

Analyze YouTube videos to get summaries, answer questions, and extract insights. This service provides transcript retrieval, summarization, and question answering capabilities.

Token Usage

This endpoint consumes tokens from your token balance based on the length of the video transcript and the complexity of the analysis requested.

Learn more about billing

Available Endpoints

Analyze Video

Analyze a YouTube video to get a summary or ask questions about its content.

Endpoint

POST /api/youtube/analyze

Headers

Content-Type: application/json X-API-Key: your_api_key_here

Request Body (Summary)

{ "videoUrl": "https://www.youtube.com/watch?v=video_id", "action": "summarize", "options": { "language": "en", "length": "medium" } }

Request Body (Question)

{ "videoUrl": "https://www.youtube.com/watch?v=video_id", "action": "ask", "question": "What is the main topic of the video?", "options": { "language": "en" } }
ParameterTypeRequiredDescription
videoUrlstringYesValid YouTube video URL
actionstringYesEither "summarize" or "ask"
questionstringOnly for "ask"Question to ask about the video
optionsobjectNoAdditional options (language, length)

Success Response

{ "id": "analysis-id", "type": "summarize", "response": "The main topic of the video is...", "tokensUsed": 450, "createdAt": "2023-06-15T10:30:00Z", "videoId": "video_id", "userId": "user-id" }

Get Analysis History

Retrieve a list of your past video analyses.

Endpoint

GET /api/youtube/history

Response

[ { "id": "analysis-id-1", "type": "summarize", "response": "Summary of the video content...", "tokensUsed": 450, "createdAt": "2023-06-15T10:30:00Z", "video": { "id": "video-db-id", "transcript": "Transcribed text...", "videoId": "youtube-video-id", "title": "Video Title", "channelName": "Channel Name", "thumbnail": "https://i.ytimg.com/vi/video-id/default.jpg", "duration": 600 } }, { "id": "analysis-id-2", "type": "summarize", "response": "Summary of another video...", "tokensUsed": 380, "createdAt": "2023-06-14T14:20:00Z", "video": { "id": "video-db-id-2", "transcript": "Transcribed text...", "videoId": "youtube-video-id-2", "title": "Another Video Title", "channelName": "Channel Name", "thumbnail": "https://i.ytimg.com/vi/video-id-2/default.jpg", "duration": 450 } } ]

Code Examples

Use these examples to integrate the YouTube Video Analysis API into your application. The examples show both summarization and question answering functionality.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 import requests api_key = "your_api_key_here" url = "https://your-api-domain.com/api/youtube/analyze" headers = { "Content-Type": "application/json", "X-API-Key": api_key } # Example 1: Get video summary data = { "videoUrl": "https://www.youtube.com/watch?v=video_id", "action": "summarize", "options": { "language": "en", "length": "medium" } } try: response = requests.post(url, headers=headers, json=data) response.raise_for_status() result = response.json() print(f"Summary: {result['response']}\n") print(f"Tokens used: {result['tokensUsed']}") except requests.exceptions.RequestException as e: print(f"Error: {str(e)}") # Example 2: Ask a question about the video data = { "videoUrl": "https://www.youtube.com/watch?v=video_id", "action": "ask", "question": "What is the main topic of the video?", "options": { "language": "en" } } try: response = requests.post(url, headers=headers, json=data) response.raise_for_status() result = response.json() print(f"Answer: {result['response']}\n") print(f"Tokens used: {result['tokensUsed']}") except requests.exceptions.RequestException as e: print(f"Error: {str(e)}")

Implementation Notes

The system uses multiple methods to retrieve video transcripts: 1. Primary Method: Utilizes youtubei.js for transcript retrieval 2. Fallback Method: Automatically falls back to youtube-transcript if primary method fails 3. Caching: Transcripts are cached for 7 days to improve performance and reduce API calls