AI Formulas in Google Sheets with Antbase
ยท4 min read
๐Ÿ“Š

AI Formulas in Google Sheets with Antbase

Add AI-powered formulas to Google Sheets using Apps Script and Antbase. Summarize, classify, extract data, and generate text in cells.

google-sheetsproductivityno-code

There is a whole category of AI work that happens in spreadsheets: classifying support tickets, extracting company names from emails, summarizing customer feedback, translating product descriptions. People do this by copying text into ChatGPT, pasting the result back, and repeating 500 times. It is mind-numbing, error-prone, and takes hours. Custom AI formulas in Google Sheets solve this, but the cost math gets ugly โ€” 500 rows times $0.01 per GPT-4 call adds up, especially if the sheet recalculates and re-triggers all 500.

Antbase makes spreadsheet AI economically viable at any scale. Most spreadsheet AI tasks are simple: classification, extraction, short summaries. These are exactly the tasks that fast free models handle perfectly. When you call Antbase from a Google Sheets formula, it routes each cell to the cheapest model that can handle the task โ€” which for classification and extraction is usually a free model. You can process 1,000 rows of support tickets at effectively zero AI cost.

The setup takes five minutes: paste an Apps Script function, set your API key, and start using =AI() as a formula. No Python scripts, no CSV exports, no API integration platform. Just a spreadsheet that can suddenly classify, summarize, translate, and extract data from any cell. For operations teams and analysts, this is transformative.

Google Sheets can call Antbase via Apps Script to create AI-powered formulas. Summarize paragraphs, classify support tickets, extract entities, or generate content โ€” all from a spreadsheet cell. Antbase routes each call to the cheapest suitable model.

Apps Script Setup

Open your Google Sheet, go to Extensions > Apps Script, and paste this code:

javascript
const ANTBASE_API_KEY = PropertiesService.getScriptProperties().getProperty('ANTBASE_API_KEY');

function AI(prompt, systemPrompt) {
  const messages = [];
  if (systemPrompt) {
    messages.push({ role: 'system', content: systemPrompt });
  }
  messages.push({ role: 'user', content: prompt });

  const response = UrlFetchApp.fetch('https://antbase.ai/v1/chat/completions', {
    method: 'post',
    contentType: 'application/json',
    headers: { Authorization: 'Bearer ' + ANTBASE_API_KEY },
    payload: JSON.stringify({
      model: 'auto',
      messages: messages,
      temperature: 0.3,
    }),
  });

  const json = JSON.parse(response.getContentText());
  return json.choices[0].message.content.trim();
}

Set your API key: in Apps Script, go to Project Settings > Script Properties and add ANTBASE_API_KEY with your key.

Usage in Cells

text
=AI("Summarize this: " & A2)
=AI(A2, "Classify this support ticket as: bug, feature, question")
=AI("Extract the company name from: " & A2)
=AI("Translate to Spanish: " & A2)

Tips

  • โ€ขApps Script has a 6-minute execution limit. For bulk processing, use a batch function that processes rows in a loop.
  • โ€ขCache results to avoid re-calling the API when the sheet recalculates. Use CacheService in Apps Script.
  • โ€ขSet temperature to 0.3 or lower for classification tasks to get consistent results.
  • โ€ขEach cell formula is a separate API call. Antbase routes simple classification to fast free models, keeping costs low even with hundreds of rows.

Try ANT routing today

Drop-in OpenAI-compatible API. Change your base URL and every request gets intelligent routing across 30+ providers.