How to search YouTube from JavaScript
Checked on 2026-11-24.
From JavaScript a YouTube search is one GET request to the Data API's search.list, made from Node.js or, with the key kept on a server, for a web page. The limit to plan around is the quota: by default a project gets 100 search calls a day, and each returns at most 50 results. Below: the request with fetch and with Google's googleapis package, what the quota means in practice, and an HTTP API without the daily cap.
1. search.list with fetch
You need a Google Cloud project with the YouTube Data API v3 enabled and an API key. Searching public videos needs no OAuth: the getting-started page says that "unauthorized requests only retrieve public data", and its examples pass the key as key=YOUR_API_KEY. The address and parameters are those of the search.list reference. Save this as search.mjs and run it with Node.js 18 or newer:
const url = new URL('https://www.googleapis.com/youtube/v3/search');
url.search = new URLSearchParams({
part: 'snippet',
q: 'web scraping tutorial',
type: 'video', // channel, playlist, video; the default is all three
maxResults: '25', // 0 to 50, the default is 5
order: 'relevance', // date, rating, title, videoCount, viewCount
key: process.env.YOUTUBE_API_KEY,
});
const res = await fetch(url);
if (!res.ok) throw new Error('search.list answered ' + res.status);
const page = await res.json();
for (const item of page.items) {
console.log(item.id.videoId, item.snippet.publishedAt, item.snippet.title);
}Other filters from the reference: publishedAfter (an RFC 3339 date-time), regionCode (a two-letter country code), relevanceLanguage, and videoDuration, where short means "less than four minutes long" and long "longer than 20 minutes". Further pages come with pageToken set to the nextPageToken of the answer.
A result is a search result resource: the ID, and a snippet with publish time, channel ID and name, title, description, thumbnails and liveBroadcastContent. It has no view count and no duration. For those, pass the IDs to videos.list:
const ids = page.items.map((item) => item.id.videoId).join(',');
const details = new URL('https://www.googleapis.com/youtube/v3/videos');
details.search = new URLSearchParams({ part: 'statistics,contentDetails', id: ids, key: process.env.YOUTUBE_API_KEY });
const videos = await (await fetch(details)).json();
for (const video of videos.items) {
console.log(video.id, video.statistics.viewCount, video.contentDetails.duration); // duration such as PT15M33S
}2. The googleapis package
Google's Node.js client wraps the same request. This combines the README's API-key example with the search.list call of the library's own YouTube sample:
// npm install googleapis
const { google } = require('googleapis');
const youtube = google.youtube({ version: 'v3', auth: process.env.YOUTUBE_API_KEY });
async function main() {
const res = await youtube.search.list({
part: 'snippet',
q: 'web scraping tutorial',
type: 'video',
maxResults: 25,
});
for (const item of res.data.items) {
console.log(item.id.videoId, item.snippet.title);
}
}
main().catch(console.error);Know its status before you build on it: the README says these libraries "are considered complete and are in maintenance mode", with critical bugs and security issues fixed but no new features. Google also publishes the YouTube client on its own as @googleapis/youtube, if you would rather not install the whole package. For one GET request, fetch needs no dependency at all.
What 100 searches a day means
The reference states the cost plainly: "100 calls per day. A call to this method has a quota cost of 1 unit in the Search Queries quota bucket." Searches are counted apart from everything else, a change the revision history announced on 1 June 2026: a project has "a default quota allocation of 100 search.list calls, 100 videos.insert calls, and 10,000 units per day combined for all other endpoints", and Google adds that the default is "subject to change". In practice:
- Every page is a call. With
maxResultsat 50, a project sees at most 5,000 search results a day, and one query paged ten deep uses a tenth of the day. - Mistakes count. "All API requests, including invalid requests, incur at least a one-point quota cost."
- Details are cheap.
videos.listcosts 1 unit from the 10,000, so adding view counts to each page of results does not touch the search bucket. - More is possible. Google takes requests for a higher quota through its quota extension request form.
Older tutorials say a search costs 100 units of the 10,000; the documentation now puts searches in their own bucket at 1 unit each. When that bucket is empty, the guide to the quota exceeded error explains what to do.
In the browser: keep the key on a server
An API key in code that ships to the browser can be read by anyone who opens your page, and every search made with it comes out of your project's 100. Google's guidance on API keys warns that "Publicly exposing your API keys can lead to unexpected charges on your account or unauthorized access to your data", and recommends this pattern: "The client should pass requests to the server, which can add the credential and issue the request." Put the search behind a small endpoint of your own, and restrict the key in the Google Cloud console as well.
3. An HTTP API without the daily cap
With Pipefetch a search is one HTTPS request, and each result already carries its view count, duration and channel. The same rule about the key applies: call it from your server.
const url = new URL('https://pipefetch.com/v1/youtube/search');
url.search = new URLSearchParams({
q: 'web scraping tutorial',
limit: '20', // 1 to 40
sort: 'relevance', // popularity, newest, mostViewed
uploaded: 'month', // hour, today, week, month, year
});
const res = await fetch(url, {
headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY },
signal: AbortSignal.timeout(90_000),
});
if (res.status === 404) {
console.log('No results'); // not charged
} else if (res.ok) {
const { data } = await res.json();
for (const video of data.results) {
console.log(video.viewCount, video.durationSeconds, video.channel.name, video.title);
}
}type switches to short, channel, playlist or all; country and lang set where and in which language the search is run. Each result has its type, ID, address, title, description, publishedAt, durationSeconds, viewCount, position and channel. publishedAt can be worked out from a label such as "4 years ago", in which case publishedAtPrecision is estimated. The npm package pipefetch makes the same request with pf.search('web scraping tutorial', { limit: 20 }). The reference lists every parameter and field.
Where it stops: up to 40 results per search and no further pages, so it is the top of a search, not a deep crawl. A search costs 1 credit whatever the number of results, one that finds nothing answers 404 and costs nothing, and there is no daily cap. Most requests take 2 to 9 seconds. It is not an official API, and Pipefetch is not affiliated with YouTube or Google. A new account has 100 free credits and needs no card. The same search from Python is in the guide to searching YouTube from Python.
Which one should you use?
| Situation | Use |
|---|---|
| A few dozen searches a day, and you already have a Google Cloud project | search.list with fetch |
| An app that already uses Google's Node.js client for other APIs | The googleapis package |
| Results deeper than 40, through pages | search.list, within its 100 calls |
| Hundreds of searches a day, or view counts in the same answer | An HTTP API such as Pipefetch |
Try it with 100 free credits. No card needed. No Google Cloud project or OAuth. Get an API key or read the docs.
APIs used in this guide
-
1 credit
YouTube Video API
Exact views, likes and comment count, description, tags, chapters and channel for one video.
GET /v1/youtube/video -
1 credit
YouTube Search API
YouTube search results for a query, with the same sorting and filters the site offers.
GET /v1/youtube/search
More YouTube guides
- How to get a YouTube transcript in Python
- How to get a YouTube transcript in Node.js
- YouTube API quota exceeded: what the error means and how to fix it
- How to find a YouTube channel ID from a handle or URL
- How to download YouTube subtitles as SRT or VTT
- youtube-transcript-api RequestBlocked or IpBlocked: why it happens and how to fix it
- How to get YouTube comments in Python
- How to search YouTube from Python
- How to list a YouTube channel's videos in Python
- How to summarize a YouTube video with an LLM in Python
- How to get YouTube transcripts and video stats in Google Sheets
- How to get YouTube video views and likes in Python
- How to get YouTube transcripts in n8n, Make and Zapier
- LangChain YoutubeLoader fails on a server: why, and a loader that works
- How to get a YouTube channel's subscriber count in Python
- How to give Claude or Cursor access to YouTube (MCP server)
- How to get YouTube comments in Node.js
- How to analyze YouTube comments with an LLM in Python
- How to list a YouTube channel's Shorts in Python
Guides for other sources
Every source
- How to get an Instagram follower count in Python
- Instagram Basic Display API alternatives: what to use after the shutdown
- Instaloader 401 Unauthorized, 429 and "Login required": what to do
- How to calculate an Instagram engagement rate in Python
- How to get an Instagram follower count in Node.js
- How to get Instagram follower counts in Google Sheets
- How to get Instagram Reel views in Python
Websites
- Clearbit Logo API alternatives: get a company logo from its domain
- How to extract email addresses from a website in Python
- How to turn a web page into Markdown in Python
- How to detect what a website is built with, in Python
- How to get the contact emails and phone numbers of websites in Google Sheets
- How to build a LangChain tool that reads web pages and searches Google
- How to turn a web page into Markdown in JavaScript for RAG
- How to extract social media links from a website in Python
- How to get a website's favicon in Python
- How to check robots.txt in Python before you fetch a page
TikTok
- How to get a TikTok video's views and likes in Python
- How to get the comments of a TikTok video in Python
- How to get a TikTok follower count in Python
- TikTok Research API: who can get access, and what to do if you cannot
- How to get TikTok video views, likes and shares in Node.js
- How to get TikTok views, likes and follower counts in Google Sheets
- How to get a Facebook Page's posts without app review
- Is there a Facebook Marketplace API?
- Facebook Groups API alternatives after its removal in 2024
- How to get a Facebook Page's follower count and contact details in Python
- How to get Google search results in Python
- pytrends 429 TooManyRequestsError: what it means and what to do
- How to get Google Trends data in Python
- Why is Wyoming first in Google Trends?
- How to get Google search results in Node.js
- How to get Google search results into Google Sheets
- How to give an LLM live Google results with tool calling
Threads
- How to get LinkedIn company data in Python
- How to search LinkedIn jobs from Python
- How to get a LinkedIn company page's latest posts in Python