I'm using Youtube API, I'd like to have a search auto-complete feature, just like on YouTube, when you type into the search input box, it gives you search suggestions. I've read the docs, but still missing, Is this possible using the API?
7 Answers
Ok I found this URL:
http://suggestqueries.google.com/complete/search?client=firefox&ds=yt&q=Query
It isn't part of Youtube API, but still works, returns a JSON response.

- 1,981
- 1
- 20
- 28
-
1That's pretty dang cool... how did you find it, by looking at the network requests for the youtube search? – Aditya M P Dec 06 '14 at 19:36
-
1we are not getting data in json , it is downoading in .txt file? – Faisal Ashraf Apr 21 '15 at 10:04
-
3how can we get suggest in json form , from this link .http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&q=tum+mile – Faisal Ashraf Apr 21 '15 at 10:05
-
This doesn't work with AJAX requests because the response lacks CORS headers :( – Vicky Chijwani May 10 '17 at 22:05
-
1It's "The Google Way" :D Sure they have some reasons for that hack https://codepen.io/vyachkonovalov/pen/XRYpgB?editors=0012 – crabvk May 15 '17 at 05:31
For json just add "client" parameter:
http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&client=firefox&q=Query

- 71
- 1
- 2
-
This is exactly what is needed, made an example based on this http://codepen.io/OfficialAntarctica/pen/oxQQPB – Zed May 03 '16 at 09:32
-
is it possible to get data response direct in json?? its downloading .txt file – Vijaysinh Parmar Jun 05 '17 at 10:13
Above all apis are old and give google search suggestion not youtube search suggestion
Use this:
https://clients1.google.com/complete/search?client=youtube&gs_ri=youtube&ds=yt&q=faded
Extract suggestions using following JS code:
// data is response of above api
const data = 'window.google.ac.h(["faded",[["faded",0,[433]],["faded alan walker lyrics",0,[433]],["faded remix",0,[433]],["faded 8d",0,[433]],["faded piano",0,[433]],["faded wheel free fire",0],["faded karaoke",0,[433]],["faded ringtone",0,[433]],["faded instrumental",0,[433]],["faded live",0,[433]],["faded piano tutorial",0,[433]],["faded whatsapp status",0,[433]],["faded dhol cover",0,[433]],["faded dance",0,[433]]],{"k":1,"q":"_sPyvXmmbfcsVtfP4sgjOdKQAvg"}])';
const searchSuggestions = [];
data.split('[').forEach((ele, index) => {
if (!ele.split('"')[1] || index === 1) return;
return searchSuggestions.push(ele.split('"')[1]);
});
console.log(searchSuggestions);

- 19,824
- 17
- 99
- 186

- 1,087
- 1
- 11
- 16
-
Can `localhost` uses this api? I'm having the `Origin https://localhost:8080 is not allowed by Access-Control-Allow-Origin.` error. – Marson Mao Oct 27 '20 at 07:28
Check Out YouTube AutoComplete Keyword Scraper . Not really sure of the context the person asking the question wants YouTube auto complete solution for but I thought I would throw this out there.

- 33
- 6
Also you can use JSON:
url: "https://suggestqueries.google.com/complete/search?client=youtube&ds=yt&q=" + i,
dataType: "jsonp",

- 2,458
- 10
- 44
- 49
The official one:
https://suggestqueries-clients6.youtube.com/complete/search?client=youtube-reduced&hl=en&gs_ri=youtube-reduced&ds=yt&cp=3&gs_id=100&q=Nectar&xhr=t&xssi=t&gl=us
You can choose country too.
P.S. I searched for Nectar in country US

- 21
- 1
After making the fetch request
const res = await fetch(
`https://clients1.google.com/complete/search?client=youtube&gs_ri=youtube&ds=yt&q=${searchTerm}`,
);
const str = await res.text();
// const str = window.google.ac.h(["faded",[["faded",0,[433]],["faded alan walker lyrics",0,[433]],["faded remix",0,[433]],["faded 8d",0,[433]],["faded piano",0,[433]],["faded wheel free fire",0],["faded karaoke",0,[433]],["faded ringtone",0,[433]],["faded instrumental",0,[433]],["faded live",0,[433]],["faded piano tutorial",0,[433]],["faded whatsapp status",0,[433]],["faded dhol cover",0,[433]],["faded dance",0,[433]]],{"k":1,"q":"_sPyvXmmbfcsVtfP4sgjOdKQAvg"}])'
You can parse the response directly by first cutting the unnecessary pieces
const arr = JSON.parse(str.substring(str.indexOf("["), str.indexOf("])") + 1));
Here is the shape of the result
let suggestionsTuple: [string, number, number[]][] = [];
All we need is to filter out the string
s
if (Array.isArray(arr) && Array.isArray(arr.at(1))) {
suggestionsTuple = arr.at(1);
}
const suggestions = suggestionsTuple.flatMap((suggestion) => suggestion).filter((suggestion) => typeof suggestion === "string"); // ["faded" ,"faded alan walker lyrics", ...]

- 1
- 1