Skip to main content
The YouTube tool lets an agent search videos, fetch details, and pull transcripts.

Overview

YouTube tool allows you to search videos, get video details, and extract transcripts.

Installation

pip install "praisonai[tools]"

Environment Variables

export YOUTUBE_API_KEY="${YOUTUBE_API_KEY:?Set YOUTUBE_API_KEY in your shell}"  # Optional for basic features

Quick Start

1

Simple Usage

from praisonai_tools import YouTubeTool

# Initialize
youtube = YouTubeTool()

# Search
results = youtube.search("Python tutorials")
print(results)
2

With Configuration

Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.

How It Works

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import YouTubeTool

agent = Agent(
    name="VideoResearcher",
    instructions="You help find and summarize YouTube videos.",
    tools=[YouTubeTool()]
)

response = agent.chat("Find videos about machine learning basics")
print(response)

Available Methods

search(query, max_results=5)

Search YouTube videos.
from praisonai_tools import YouTubeTool

youtube = YouTubeTool()
videos = youtube.search("AI tutorials", max_results=5)

get_video(video_id)

Get video details.
video = youtube.get_video("dQw4w9WgXcQ")

get_transcript(video_id)

Get video transcript.
transcript = youtube.get_transcript("dQw4w9WgXcQ")

Common Errors

ErrorCauseSolution
youtube-transcript-api not installedMissing dependencyRun pip install youtube-transcript-api
Transcript not availableNo captionsTry different video
Rate limitedToo many requestsAdd delays

Best Practices

Basic transcript features work without a key, but video search needs YOUTUBE_API_KEY. Set it in your shell or .env.
search(query, max_results=5) defaults to 5. Keep it low so the agent processes fewer videos per query.
Not every video has captions. Wrap get_transcript(video_id) in try/except so the agent can skip or report videos without transcripts.

Spotify

Music search

Wikipedia

Knowledge base