YouTube’s massive content library contains billions of videos. If you're building an app, dashboard, or automation tool, you might want to search and retrieve YouTube videos programmatically. That’s where the YouTube Search API, part of the YouTube Data API v3, comes into play.
In this guide, we’ll cover everything you need to know to search YouTube videos using the YouTube API, including:
How the YouTube Search API works
Setting up your API access
Making requests to search videos
Filtering by keyword, channel, category, or time
Handling and displaying the results
The YouTube Search API is a feature within the YouTube Data API v3 that allows developers to search for public YouTube videos, channels, and playlists.
Using a single HTTP request, you can query YouTube by keywords and receive a structured JSON response containing video details like:
Video ID
Title
Description
Thumbnails
Channel name
Publish date
This enables developers to power custom search engines, bots, dashboards, content analyzers, and more.
To use the API, you need a free API key from Google.
Create a new project or select an existing one.
Click on “APIs & Services” → Library
Search for YouTube Data API v3, and click Enable
Go to Credentials, and click Create Credentials → API Key
Copy your API key and keep it secure
YouTube API uses a simple HTTP GET request. Here's the basic format:
https://www.googleapis.com/youtube/v3/search?part=snippet&q=YOUR_QUERY&type=video&key=YOUR_API_KEY
To search for “how to cook biryani”:
https://www.googleapis.com/youtube/v3/search?part=snippet&q=how+to+cook+biryani&type=video&maxResults=5&key=YOUR_API_KEY
part=snippet: Fetches video metadata like title, thumbnails, etc.
q=how+to+cook+biryani: Your search query
type=video: Only return videos (not channels or playlists)
maxResults=5: Number of results per page (max is 50)
key=YOUR_API_KEY: Your API key
The response is a JSON object. Each item includes details like this:
{
"items": [
{
"id": {
"videoId": "AbCdEf12345"
},
"snippet": {
"title": "How to Cook Biryani - Step by Step",
"description": "Learn how to make delicious biryani...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/AbCdEf12345/default.jpg"
}
},
"channelTitle": "Indian Food TV",
"publishedAt": "2023-11-01T14:23:45Z"
}
}
]
}
From here, you can extract:
videoId
title
description
thumbnail.url
channelTitle
publishedAt
To generate a link to the video:
https://www.youtube.com/watch?v=AbCdEf12345
The API allows multiple filters to refine results.
Use the publishedAfter or publishedBefore parameters (in ISO 8601 format):
&publishedAfter=2024-01-01T00:00:00Z
Search only within a specific channel:
&channelId=UCx123abcXYZ
You can get a channel's ID from their "About" section or via another API call.
Choose how results are sorted:
order=date (most recent)
order=rating
order=relevance (default)
order=title
order=viewCount
Example:
&order=viewCount
videoDuration=short (less than 4 minutes)
videoDuration=medium (4–20 minutes)
videoDuration=long (more than 20 minutes)
YouTube Search API returns a maximum of 50 results per page. To get more results, use the nextPageToken from the response.
Example structure:
{
"nextPageToken": "CBkQAA",
"items": [...]
}
Use that token in your next request:
&pageToken=CBkQAA
<!DOCTYPE html>
<html>
<head><title>YouTube Search</title></head>
<body>
<input id="query" placeholder="Search...">
<button onclick="search()">Search</button>
<div id="results"></div>
<script>
async function search() {
const q = document.getElementById('query').value;
const res = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(q)}&type=video&maxResults=5&key=YOUR_API_KEY`);
const data = await res.json();
const results = document.getElementById('results');
results.innerHTML = '';
data.items.forEach(item => {
const videoId = item.id.videoId;
const title = item.snippet.title;
const thumb = item.snippet.thumbnails.default.url;
results.innerHTML += `<div>
<img src="${thumb}"> <a href="https://youtube.com/watch?v=${videoId}" target="_blank">${title}</a>
</div>`;
});
}
</script>
</body>
</html>
Just replace YOUR_API_KEY with your actual key, and you have a working search tool.
YouTube Search requests cost 100 quota units each.
Your API project gets 10,000 units/day by default.
You can request more quota from Google if needed.
Build a custom search engine
Monitor niche content for trends
Pull video metadata into a spreadsheet or app
Filter competitor content
Alert system for new uploads
403 Quota Exceeded
You’ve used up your daily quota. Try reducing the number of requests or apply for a quota increase.
400 Missing Required Parameter
Check that all required parameters like part=snippet are included.
API Key Not Valid
Make sure your API key is active and authorized to access the YouTube Data API.
The YouTube Search API is a powerful and flexible tool for developers, analysts, and content managers. Whether you want to track video performance, build your own frontend search, or automate reporting, the API gives you direct access to YouTube’s public video data.
By learning how to construct requests, apply filters, and parse results, you can create efficient workflows and tools tailored to your project.
If you’re interested in building on this, consider looking into the YouTube Analytics API or integrating search results into Google Sheets or Apps Script for powerful reporting dashboards.