A powerful Google Apps Script that brings AI capabilities directly to your Google Sheets using the Groq API. Transform your spreadsheets into intelligent data analysis tools with just a few clicks.
- Direct AI Integration: Send prompts to Groq AI models directly from spreadsheet cells
- Smart Context Processing: Automatically format spreadsheet data as context for AI analysis
- Header Detection: Intelligently recognizes and formats data with headers
- Error Handling: Comprehensive error handling with user-friendly messages
- Debug Logging: Built-in logging for troubleshooting and development
- Flexible Input: Support for both range references and single cell values
- Simple Setup: Copy-paste script into any spreadsheet
- Reliable: Works immediately after setup
- A Google account with access to Google Sheets
- A Groq API key (Get one here)
- Basic familiarity with Google Apps Script
Why This Approach Works:
- β Copy-paste setup: Simple and straightforward
- β Works immediately: No complex library or deployment issues
- β Per-spreadsheet control: Each spreadsheet has its own copy
- β Easy troubleshooting: Clear error messages and logging
- β No Google Apps Script limitations: Avoids library and web app complications
No more library bullshit, no more deployment issues, just copy-paste and use!
Google Apps Script Limitation: Unfortunately, Google Apps Script doesn't provide a native way to make custom functions globally available across all your spreadsheets automatically. This is a platform limitation, not a flaw in this script.
What this means:
- Each spreadsheet needs its own copy of the script
- You need to repeat the installation steps for each spreadsheet
- There's no "install once, use everywhere" solution with Google Apps Script custom functions
Why we use this approach:
- It's the most reliable method available
- Works consistently without complex workarounds
- Easy to understand and troubleshoot
- No false promises about global availability
- Open the Google Sheet where you want to use the GROQ function
- Go to Extensions β Apps Script
- This opens the Apps Script editor for this specific spreadsheet
- Delete any existing code in the editor
- Copy the entire content from
groq.gs - Paste it into the Apps Script editor
- Save the project (Ctrl+S or Cmd+S)
- In the Apps Script editor, go to Project Settings (gear icon)
- Scroll down to Script Properties
- Click Add script property
- Set:
- Property:
GROQ_API_KEY - Value: Your Groq API key
- Property:
- Click Save
- Go back to the main Apps Script editor
- Click Run β Run function β GROQ
- When prompted, click Authorize access
- Choose your Google account
- Click Allow
That's it! Now you can use =GROQ(prompt, contextRange) in this spreadsheet.
Repeat these steps for each spreadsheet where you want to use the GROQ function.
=GROQ(prompt, contextRange)Note: You need to repeat the installation steps for each spreadsheet where you want to use the GROQ function.
prompt(required): The text instruction to send to the AIcontextRange(optional): A spreadsheet range (e.g., A1:E10) or single cell whose data will be included as context
=GROQ("What is the capital of France?")
=GROQ("Summarize this sales data", A1:E20)
=GROQ("Translate to Spanish", B1)
=GROQ("What's the trend in this data?", C2:C50)
The script intelligently formats your spreadsheet data:
If your data has headers in the first row:
Name: John, Age: 25, City: New York
Name: Jane, Age: 30, City: Los Angeles
If no headers are detected:
John, 25, New York
Jane, 30, Los Angeles
The script uses the gemma2-9b-it model by default. You can modify this in the code:
const model = "gemma2-9b-it"; // Change to other models like "mixtral-8x7b-32768"- Temperature: 0.6 (creativity level, 0.0-1.0)
- Max Tokens: 1024 (maximum response length)
- Ensure you've set the
GROQ_API_KEYscript property correctly - Check that the property name is exactly
GROQ_API_KEY
- Your API key is invalid or expired
- Generate a new API key from the Groq console
- You've exceeded your API rate limits
- Wait a moment and try again
- The Groq API response structure has changed
- Check the Apps Script logs for detailed error information
- Make sure you've copied the script into this spreadsheet's Apps Script
- Check that you've saved the script after pasting
- Verify that you've authorized the script (Step 4)
- Ensure you've set the
GROQ_API_KEYscript property correctly - Check that the property name is exactly
GROQ_API_KEY - Make sure you're in the correct Apps Script project for this spreadsheet
The script includes comprehensive logging. To view logs:
- In Apps Script editor, click View β Execution log
- Run your function and check the logs for detailed information
=GROQ("Analyze this sales data and identify the top performing products", A1:F100)
=GROQ("Extract key insights from this customer feedback", B2:B50)
=GROQ("Create a summary of this quarterly report data", A1:Z20)
=GROQ("Translate this text to French", C1)
- Your API key is stored securely in Google Apps Script properties
- API calls are made server-side, not from your browser
- Consider setting up API key rotation for production use
- Monitor your Groq API usage to control costs
- Keep context ranges reasonable in size (avoid entire sheets)
- Use specific prompts for better results
- Consider caching responses for repeated queries
- Monitor API usage to stay within rate limits
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Kamil Stanuch - Initial work - [GitHub Profile]
Created on: 2025-07-25
- Groq for providing the AI API
- Google Apps Script team for the platform
- The open-source community for inspiration and feedback
If you encounter any issues or have questions:
- Check the troubleshooting section
- Review the Apps Script execution logs
- Open an issue on GitHub with detailed information
Note: This script requires an active internet connection and a valid Groq API key to function. API usage may incur costs depending on your Groq plan.
