YouTube
Search YouTube and get video transcripts
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 featuresQuick Start
- Simple Usage
python from praisonai_tools import YouTubeTool # Initialize youtube = YouTubeTool() # Search results = youtube.search("Python tutorials") print(results) - 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
| Error | Cause | Solution |
|---|---|---|
youtube-transcript-api not installed | Missing dependency | Run pip install youtube-transcript-api |
Transcript not available | No captions | Try different video |
Rate limited | Too many requests | Add delays |
Best Practices
Add YOUTUBE_API_KEY for search
Basic transcript features work without a key, but video search needs YOUTUBE_API_KEY. Set it in your shell or .env.
Cap max_results
search(query, max_results=5) defaults to 5. Keep it low so the agent processes fewer videos per query.
Handle missing transcripts
Not every video has captions. Wrap get_transcript(video_id) in try/except so the agent can skip or report videos without transcripts.