Back to Blog
TutorialsJune 25, 20257 min read

How to Use a Free LLM API in Google Sheets (AI in Spreadsheets — No Code)

Add AI superpowers to Google Sheets using a free LLM API key — summarize text, classify data, generate content, and analyze rows with a custom formula.

Why AI in Google Sheets Is Incredibly Useful

Most business data lives in spreadsheets. If you could run an LLM on each row — summarizing customer feedback, classifying support tickets, translating text, extracting structured data from messy notes — you would eliminate hours of manual work every week. The good news: you can do this with Google Sheets, Google Apps Script, and a free API key from FreeLLMKeys. No external software, no paid tools.

What You Can Build

  • =AI_SUMMARIZE(A1) — Summarize any text cell
  • =AI_CLASSIFY(A1, "positive,negative,neutral") — Classify sentiment
  • =AI_EXTRACT(A1, "email") — Extract specific data from unstructured text
  • =AI_TRANSLATE(A1, "Spanish") — Translate to any language
  • =AI_PROMPT(A1, B1) — Run any custom prompt on cell content

Step 1 — Open Apps Script

In your Google Sheet, click Extensions → Apps Script. This opens the script editor where you will write JavaScript that calls the LLM API.

Step 2 — Write the AI Functions

Paste this code into the Apps Script editor and save it (Ctrl+S):

const API_KEY  = "sk-your-freellmkeys-key";  // paste from FreeLLMKeys.com
const BASE_URL = "https://aiapiv2.pekpik.com/v1/chat/completions";
const MODEL    = "gpt-4o";

function callLLM_(systemPrompt, userContent) {
  const payload = {
    model: MODEL,
    messages: [
      { role: "system",  content: systemPrompt },
      { role: "user",    content: String(userContent) }
    ],
    max_tokens: 256,
    temperature: 0.1
  };

  const options = {
    method: "post",
    contentType: "application/json",
    headers: { Authorization: "Bearer " + API_KEY },
    payload: JSON.stringify(payload),
    muteHttpExceptions: true
  };

  const response = UrlFetchApp.fetch(BASE_URL, options);
  const json     = JSON.parse(response.getContentText());

  if (json.error) throw new Error(json.error.message);
  return json.choices[0].message.content.trim();
}

/** Summarize the content of a cell in 1-2 sentences */
function AI_SUMMARIZE(text) {
  if (!text) return "";
  return callLLM_("Summarize the following text in 1-2 sentences. Be concise.", text);
}

/** Classify text into one of the provided categories */
function AI_CLASSIFY(text, categories) {
  if (!text) return "";
  return callLLM_(
    `Classify the text into exactly one of these categories: ${categories}. Reply with only the category name, nothing else.`,
    text
  );
}

/** Extract a specific piece of information from text */
function AI_EXTRACT(text, field) {
  if (!text) return "";
  return callLLM_(
    `Extract the ${field} from the following text. Return only the extracted value, nothing else. If not found, return "N/A".`,
    text
  );
}

/** Translate text to the target language */
function AI_TRANSLATE(text, targetLanguage) {
  if (!text) return "";
  return callLLM_(
    `Translate the following text to ${targetLanguage}. Return only the translation, nothing else.`,
    text
  );
}

/** Run a custom prompt on cell content — most flexible function */
function AI_PROMPT(text, customPrompt) {
  if (!text || !customPrompt) return "";
  return callLLM_(customPrompt, text);
}

Step 3 — Use the Functions in Your Sheet

Now you can use these as regular spreadsheet formulas. Examples:

=AI_SUMMARIZE(A2)
=AI_CLASSIFY(B2, "positive,negative,neutral")
=AI_EXTRACT(C2, "phone number")
=AI_TRANSLATE(D2, "French")
=AI_PROMPT(E2, "Write a polite reply to this customer complaint in under 50 words")

Step 4 — Batch Processing an Entire Column

To classify an entire column of customer reviews, type the formula in the first result cell and drag it down. Apps Script will call the API for each row. Note: if you have hundreds of rows, add a small delay to avoid rate limits:

function classifyAllReviews() {
  const sheet   = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const reviews = sheet.getRange("A2:A100").getValues();

  reviews.forEach((row, i) => {
    if (!row[0]) return;
    const result = AI_CLASSIFY(row[0], "positive,negative,neutral");
    sheet.getRange(i + 2, 2).setValue(result);
    Utilities.sleep(500); // 500ms delay between calls to stay within rate limits
  });
}

Run this function from the Apps Script editor (Run → classifyAllReviews) and it will classify all 100 reviews automatically.

Switching to a Faster or Different Model

Change the MODEL constant at the top of the script to switch models:

const MODEL = "gemini-2.5-flash";  // Fastest — good for large batches
const MODEL = "deepseek-chat";      // Best for extraction and classification
const MODEL = "claude-sonnet-4-6";  // Best for summarization and writing

Real-World Use Cases

  • E-commerce: Classify product reviews by sentiment and topic automatically
  • Sales: Summarize call notes from column A into one-line action items in column B
  • HR: Extract skills from unstructured resume text into structured columns
  • Support: Auto-classify incoming support tickets by category and urgency
  • Marketing: Translate product descriptions to multiple languages in bulk

Google Sheets + a FreeLLMKeys key is one of the most practical ways to bring AI into a real workflow. No web app to build, no UI to design — just a spreadsheet that got dramatically smarter.

F
FreeLLMKeys Team
Building tools for the AI developer community