What You’ll Connect
After this guide, your Google Sheets will have a custom formula that calls your own GPU-hosted LLM — no API costs, no rate limits. Type =AI_COMPLETE(A2) in any cell, and it sends the referenced text to your vLLM or Ollama endpoint on dedicated GPU hardware, returning the AI-generated response directly into the spreadsheet.
This integration uses Google Apps Script to create a custom function that calls your self-hosted inference API. Every cell becomes an AI endpoint — ideal for bulk classification, translation, summarisation, or data extraction across hundreds of rows without incurring per-token charges.
Apps Script Function –> UrlFetchApp.fetch() –> GPU Server =AI_COMPLETE(A2) reads cell value POST to /v1/chat/ vLLM inference builds prompt completions on dedicated GPU | | Cell displays <-- Function returns <-- Parse JSON response <-- Completion text AI output completion string extract content returned -->Prerequisites
- A GigaGPU server with a running LLM behind an OpenAI-compatible API (self-host guide)
- HTTPS access to your inference endpoint with a valid certificate (Nginx proxy guide)
- A Google account with access to Google Sheets and Apps Script
- API key for your GPU inference server (security guide)
Integration Steps
Open your Google Sheet and navigate to Extensions > Apps Script. This opens the script editor where you will write a custom function. Apps Script runs server-side JavaScript and can make HTTP requests via UrlFetchApp.
Define a function called AI_COMPLETE that takes a cell value (your prompt text) and an optional system instruction. The function constructs an OpenAI-compatible request payload, sends it to your GPU endpoint using UrlFetchApp.fetch(), parses the JSON response, and returns the completion text.
Save the script and return to your spreadsheet. You can now use =AI_COMPLETE(A2) in any cell. For batch processing, drag the formula down a column to process hundreds of rows. Apps Script caches results, so unchanged inputs do not re-trigger API calls.
Code Example
Add this to your Apps Script project. It connects to your FastAPI inference server on GigaGPU:
/**
* Calls self-hosted LLM on GPU server.
* @param {string} prompt The text to send to the model.
* @param {string} instruction Optional system instruction.
* @return {string} AI-generated completion.
* @customfunction
*/
function AI_COMPLETE(prompt, instruction) {
if (!prompt) return "";
const sysMsg = instruction || "You are a helpful assistant. Be concise.";
const GPU_URL = "https://your-gpu-server.gigagpu.com/v1/chat/completions";
const payload = {
model: "meta-llama/Llama-3-70b-chat-hf",
messages: [
{ role: "system", content: sysMsg },
{ role: "user", content: String(prompt) }
],
max_tokens: 300,
temperature: 0.2
};
const options = {
method: "post",
contentType: "application/json",
headers: { "Authorization": "Bearer " + PropertiesService.getScriptProperties().getProperty("GPU_API_KEY") },
payload: JSON.stringify(payload),
muteHttpExceptions: true
};
const response = UrlFetchApp.fetch(GPU_URL, options);
const data = JSON.parse(response.getContentText());
return data.choices[0].message.content.trim();
}
Testing Your Integration
First, set your API key in Apps Script: go to Project Settings > Script Properties and add GPU_API_KEY with your key value. Then in the spreadsheet, enter a prompt in cell A2 (e.g., “Classify this as positive or negative: Great product, fast delivery”) and type =AI_COMPLETE(A2) in B2. The cell should display the AI response after a few seconds.
Test with multiple rows to confirm batch processing works. Apps Script has a 6-minute execution limit per call and a 30-second UrlFetchApp timeout, so keep generation lengths moderate. If you hit limits, process rows in smaller batches using a triggered function rather than cell formulas.
Production Tips
Custom functions in Google Sheets recalculate when inputs change but can be slow for large datasets. For processing hundreds of rows, write a menu-triggered function instead that iterates through a range, calls the AI for each row, and writes results in bulk. This avoids per-cell recalculation delays.
Store your API key using Script Properties rather than hardcoding it. This keeps the credential hidden from sheet collaborators who might view the Apps Script code. For additional security, route requests through a middleware that validates the calling sheet’s identity.
Google Sheets with AI formulas work well for teams doing bulk content operations — product description generation, review sentiment analysis, or lead scoring. Pair with a self-hosted API running open-source models for predictable costs regardless of volume. Browse more tutorials or get started with GigaGPU dedicated GPU hosting to add AI to your spreadsheets.