Tutorial

How to Build a YouTube Research Agent

Learn how to build an AI agent that searches YouTube for tutorials, reviews, and educational content to include in research outputs.

YouTube is a massive source of tutorials, product reviews, and expert commentary that text-based search often misses. This tutorial builds a research agent that queries Scavio's YouTube endpoint to find relevant videos, extracts metadata, and incorporates video findings into research outputs. The agent can find tutorials for technical topics, product reviews for comparison content, and expert talks for market intelligence.

Prerequisites

  • Python 3.8+ installed
  • requests library installed
  • A Scavio API key from scavio.dev

Walkthrough

Step 1: Search YouTube for a topic

Query Scavio's YouTube endpoint for relevant videos.

Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def search_youtube(query: str) -> list:
    resp = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'youtube', 'query': query}, timeout=10)
    return resp.json().get('organic', [])

Step 2: Extract video metadata

Parse the search results into structured video records.

Python
def parse_videos(results: list) -> list:
    videos = []
    for r in results:
        videos.append({
            'title': r.get('title', ''),
            'url': r.get('link', ''),
            'channel': r.get('channel', ''),
            'views': r.get('views', ''),
            'published': r.get('date', ''),
            'description': r.get('snippet', ''),
        })
    return videos

Step 3: Filter by relevance and recency

Filter videos to find the most relevant and recent content.

Python
def filter_videos(videos: list, max_age_days: int = 90) -> list:
    from datetime import datetime, timedelta
    cutoff = datetime.now() - timedelta(days=max_age_days)
    filtered = []
    for v in videos:
        # Keep videos with substantial titles (not shorts or clips)
        if len(v['title']) > 20:
            filtered.append(v)
    return filtered[:10]

Step 4: Generate research summary

Compile video findings into a research-ready format.

Python
def youtube_research(topic: str) -> dict:
    results = search_youtube(topic)
    videos = parse_videos(results)
    filtered = filter_videos(videos)
    return {
        'topic': topic,
        'total_found': len(results),
        'top_videos': filtered,
        'summary': f"Found {len(results)} videos on '{topic}'. Top channels: {', '.join(set(v['channel'] for v in filtered[:5] if v['channel']))}"
    }

research = youtube_research('LangChain agents tutorial 2026')
print(research['summary'])
for v in research['top_videos'][:5]:
    print(f"  - {v['title']} ({v['channel']})")

Python Example

Python
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def yt_research(topic):
    data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'youtube', 'query': topic}, timeout=10).json()
    return [{'title': r['title'], 'url': r.get('link', ''), 'channel': r.get('channel', '')}
            for r in data.get('organic', [])[:10]]

JavaScript Example

JavaScript
async function ytResearch(topic) {
  const data = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
    body: JSON.stringify({platform: 'youtube', query: topic})
  }).then(r => r.json());
  return (data.organic || []).slice(0, 10).map(r => ({title: r.title, url: r.link, channel: r.channel}));
}

Expected Output

JSON
A research agent that finds relevant YouTube videos and compiles findings into structured research summaries.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.8+ installed. requests library installed. A Scavio API key from scavio.dev. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Learn how to build an AI agent that searches YouTube for tutorials, reviews, and educational content to include in research outputs.