Revolutionize your projects with ChatGPT and Google Sheets integration

On March 1, 2023, OpenAI finally unveiled the long-awaited ChatGPT API, and the world held its breath! Now it's never been easier to connect ChatGPT to Google Sheets to speed up your projects.

Like many users, we've been looking forward to this breakthrough to make it easier to integrate ChatGPT with Google Sheets and optimize our work in progress. Today, we'll walk you through the steps to get there using the gpt-3.5-turbo model.

How to integrate the ChatGPT API with Google Sheets using Google Apps Script

Step 1: Get an API key

To get started, you'll need an API key from OpenAI. Log in to your OpenAI account and create your API key.

Step 2: Access Apps Scripts

In Google Sheets, click on “Extensions” in the main menu, then select “Apps Script”. Copy the provided code into the Apps Script code editor and remember to add your own unique API key in place of “YOUR API KEY” on the first line.

Save your changes and return to Google Sheets. You may need to grant some permissions to Google to get everything working properly.

Step 3: Using the ChatGPT API in Google Sheets

Return to Google Sheets. Explaining in detail how to use the prompts and spreadsheet layout is beyond the scope of this basic guide, but we're confident you'll quickly learn how to take advantage of this integration.

const MAX_TOKENS = 600;
const TEMPERATURE = 0.7;

function AI_Consultive(prompt, temperature = 0.4, model = "gpt-3.5-turbo") {
  const url = "";
  const payload = {
    model: model,
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: prompt },
    temperature: TEMPERATURE,
    max_tokens: MAX_TOKENS,
  const options = {
    contentType: "application/json",
    headers: { Authorization: "Bearer " + SECRET_KEY },
    payload: JSON.stringify(payload),
  const res = JSON.parse(UrlFetchApp.fetch(url, options).getContentText());
  return res.choices[0].message.content.trim();

To give you a quick example, if you have a topic title in cell A1, you can insert the following formula into any other cell and watch the magic happen:

=AI_Consultive("Create an introductory paragraph for this topic : "&A1&".")

Of course, this is just a basic example to show how the ChatGPT API works properly with Google Sheets. Now it's up to you to let your imagination run wild and explore all the possibilities offered by this fantastic integration!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *