AI for Sheets.
AI Integration for Google Sheets.
This beginner-friendly guide will help you set up AI-powered content generation right in your Google Sheets. No coding experience required!
What You Need Before Starting
- A Google account (like the one you use for Gmail)
- An OpenAI API key
- Go to OpenAI's website
- Click "Sign up" (or "Log in" if you already have an account)
- Once logged in, click on your profile icon โ "View API keys"
- Click "Create new secret key"
- Copy your API key and keep it safe!
Step 1: Create Your Spreadsheet
- Go to sheets.google.com
- Click the plus icon (+) to create a new spreadsheet
- Name your spreadsheet (click "Untitled spreadsheet" at the top)
Step 2: Add the AI Script
- Click "Extensions" in the top menu
- Click "Apps Script" - this will open a new tab
- You'll see a blank file named "Code.gs"
- Delete any code that's already there
- Copy and paste this code:
The script adds an OpenAI menu to Google Sheets. Select a cell with your prompt, click OpenAI โ Generate Content, and the script uses that selected cell as the input.
Step 3: Add Your API Key
- In the code above, find the line with
const apiKey = 'sk-your-api-key-here';
- Replace
sk-your-api-key-here with your actual OpenAI API key (keep the quotes!)
- Click the ๐พ Save button (or press Ctrl+S / Cmd+S)
Step 4: First-Time Setup and Authorization
When you first use the script, Google will ask for permissions. Here's what to expect:
- Go back to your spreadsheet
- Refresh the page - you should see a new "OpenAI" menu at the top
- Click "OpenAI" โ "Generate Content"
- You'll see a "Authorization Required" popup:
- Click "Continue"
- Choose your Google account
- You'll see a warning saying "Google hasn't verified this app"
- Click "Advanced" โ "Go to [Your Project Name] (unsafe)"
- Click "Allow"
These security warnings appear because you're using your own script. It's safe to proceed since you created the script yourself.
How to Use the Script
- Set up your spreadsheet:
- Column A: Your prompts
- Column B: Will contain AI responses
- You can add headers if you want (like "Prompt" and "Response")
- Using the script:
- Type your prompt in Column A (example: "Write a short product description for a coffee mug")
- Click on the cell containing your prompt
- Click the "OpenAI" menu at the top
- Wait a few seconds - the response will appear in Column B
Checking Execution Logs
If something goes wrong, you can check the execution logs:
- Go back to the Apps Script editor (Extensions โ Apps Script)
- Click "View" โ "Execution log" in the menu
- Run your script again to see what's happening
- You'll see detailed information about:
- When the script ran
- Any errors that occurred
- API responses and issues
Language Models
This script uses GPT-3.5-turbo, which is OpenAI's efficient and cost-effective language model. Key points:
- Optimized for chat-based interactions
- Good balance of performance and cost
- 4k context window (number of tokens it can process)
- Can handle various tasks like writing, analysis, and coding
For more details about available models and their capabilities, visit the
OpenAI Models Documentation.
Authorization Details
This script is set to only work with the current document. You'll see this in the authorization screen because of these permissions:
SpreadsheetApp.getActiveSheet(): Allows access to current sheet only
UrlFetchApp.fetch(): Needed to communicate with OpenAI
- This is the minimum permission level needed
Troubleshooting
If you see "Authorization Required" again:
- Your authorization might have expired
- Just follow the authorization steps again
If you get an error about the API key:
- Double-check that you copied your entire API key correctly
- Make sure you kept the quotes around the API key in the code
If nothing happens when you click "Generate Content":
- Make sure you've selected a cell that contains text
- Try refreshing the page
- Check that you're connected to the internet
This version is built around a menu command, not a cell formula. It reads the active cell, checks that it contains text, and runs generateContent() when you choose Generate Content from the menu.
Need Help?
- For API key issues: Visit OpenAI's help center
- For Google Sheets issues: Click "Help" in Google Sheets menu
- For script issues: Try refreshing the page and authorizing again
Remember: Keep your API key private and never share it with anyone!
Note: Using the OpenAI API may incur costs. Please refer to the OpenAI API pricing page for more details.
Disclaimer: Users are responsible for how they use information and code provided on this website.
More Guides
-
Free API vs. paid side panel โ step-by-step setup, real-world use cases, and which method fits your workflow.
May 23, 2026
-
Write any formula in plain English. Free and paid options compared, with prompt patterns that get better results.
May 23, 2026
-
5 methods compared โ Apps Script, add-ons, browser extensions, Zapier, and copy-paste. Honest pros and cons at every price point.
May 23, 2026
-
5 methods including conditional formatting, UNIQUE, COUNTIF, the built-in tool, and fuzzy matching for near-duplicates.
May 23, 2026
Send Feedback