Powered by MeaningCloud, with this script you can input a range of data (1000 cells max) and it will automatically cluster keywords into relevant groups (20k request per month). 🚀
Check out the GIF to see it in action 🎥

How to add the Script to Google Sheets
1. Sign up to MeaningCloud
Sign up to MeaningCloud an awesome API for text analysis and natural language processing. You get 20,000 requests per month, for free!

2. Get your API Key
Head to the subscriptions page and copy your API key.

3. Copy the script below:
/**
* Automatically assign keywords into clusters.
*
* @param {A2:A1000} range - input the range of your keywords.
* @param {"en"} language - [OPTIONAL] input the target language ('en', 'es', 'it', 'fr', 'pt'). Default set to 'en'.
* @customfunction
*/
function cluster(range, language) {
// get the range of keywords
const keywords = [];
for (i = 0; i < range.length; i++) {
keywords.push(range[i][0]);
}
// add keywords as line items for request
const txt = keywords.toString().replace(/,/g, '\n');
try {
// MeaningCloud https://api.meaningcloud.com/clustering-1.1
const apiKey = 'ADD API KEY HERE';
const lang = language || 'en';
const requestBody = {
'key': apiKey,
'txt': txt,
'lang': lang
};
const options = {
'method': 'POST',
'contentType': 'application/x-www-form-urlencoded',
'payload': requestBody
};
const response = UrlFetchApp.fetch('https://api.meaningcloud.com/clustering-1.1', options);
const result = response.getContentText();
// parse result
json = JSON.parse(result);
} catch (e) {
return 'Request to API failed. Try clustering less keywords';
}
const list = json.cluster_list;
// loop through response and create return array with cluster groups and keywords
let rows = [],
data,
title;
for (i = 0; i < list.length; i++) {
data = list[i];
title = data.title.toLowerCase();
cluster = Object.values(data.document_list);
for (j = 0; j < cluster.length; j++) {
rows.push([title, cluster[j]]);
}
}
// add headers
rows.unshift(["Cluster Group", "Keywords"]);
return rows;
}
5. Head over to Google Sheets
Or if you’re really smart, create a new sheet by going to: https://sheets.new
Select Apps Script from the Extensions menu.
Paste the script and replace line 22 with your API key:
const apiKey = 'ADD API KEY HERE';
Save it.

6. Add the formula to any cell in your sheet
=cluster(A2:A1000, "en")
You can replace A2:A1000 with any keyword range in a single column. Anything above 1000 cells tends to timeout with this custom function, though I have ran it with 2000 cells successfully. For larger sites, it will be more effective to cluster keywords using this function on a page-by-page basis.
You can also specify a language (the default is set to the ‘en’). The languages supported by MeaningCloud are ‘en’, ‘es’, ‘it’, ‘fr’, and ‘pt’.
*keywords can be part of multiple cluster groups.
How does the clustering work?
Here’s the MeaningCloud explanation:
“It groups documents together not by applying a purely textual similitude, but according to their relevance with regard to the subjects present in the collection, and automatically assigns to each cluster a title or name that represents its prevailing subject. Also, it internally employs lemmatization technologies which enable to take into account all the variants of a term, and it can be configured to consider stopwords and other linguistic aspects.”
You can find out more information by visiting their website.
Are there better ways to cluster keywords?
In short, yes. This function provides a great, quick (and free) way to automatically group keywords but there are professional clustering tools that cluster keywords based on the similarity of their search results. That means if search results from keyword a match keyword b, they’re grouped together.
With this approach you’re seeing clusters through the lens of Google (sort of) and that makes the data more meaningful. Here’s a list of some fantastic tools on the market if you want to explore this further:

Thanks for stopping by 👋
I’m Andrew Charlton, the Google Sheets nerd behind Keywords in Sheets. 🤓
Questions? Get in touch with me on social or comment below 👇
hey Andew. Thanks a lot for sharing the script. But it seems something is missing or somehow its giving me error. It says Requesting to Api failed. Shall be grateful, if you could help me resolve this.
Hi there, this is either because you’re requesting too many cells or that you’re not actually subscribed to the API. You need to both sign up to Rapid API and then subscribe to the API by following this link: https://rapidapi.com/MeaningCloud/api/text-clustering/pricing
This is next level in Sheets.
You know well to play within sheets
Thank you! 😀
Have signed up on Rapid API as per the instructions. however there is no button on the https://rapidapi.com/MeaningCloud/api/text-clustering/pricing to pay or subscribe to the basic plan. Can you guide on how do I get subscribed to the basic plan and activate the sheets.
Hey Andrew,
thanks for this script, it’s terrific!
I don’t know why, it worked for me at first but now it has stopped working for me. The request I make is 450 keywords and it’s been more than a month since I made any request.
Does it work for you guys?
Thank you for your help!
Best,
Oleh
Hey,
Meaningcloud were having a few issues, but the API is now working for me via RapidAPI. Could you check again please and let me know?
Thanks,
Andrew