SheetMagicSheetMagic

Functions vs Add-ons vs API: Cheapest AI in Google Sheets

Apps Script custom functions, marketplace add-ons, or direct API calls? The cheapest choice is the one that costs you the fewest hours to build and keep running. Honest tradeoffs on setup time, total cost, and what each one can actually do.

Phil Nguyen · 8 min read · Updated

There are three ways to put AI inside Google Sheets: write an Apps Script custom function, install a marketplace add-on, or call an AI API from outside the sheet. The right pick is the one with the lowest total cost once you count the hours to build and maintain it, not just the API bill.

Take a marketing manager with 500 products that need descriptions. Copy-pasting each one through ChatGPT at an assumed minute a row is over 8 hours of tab-switching. Any of the three options below gets that down to one formula or one script run. What differs is how many hours you spend before that works, and how many you spend keeping it working.

This is an honest look at all three.


Option 1: Custom functions with Apps Script

Google Sheets lets you write JavaScript in the built-in Apps Script editor (Extensions > Apps Script). You can make a custom function that calls an AI API and puts the result in a cell.

Here is what a basic version looks like:

function AI(prompt) {
  const apiKey = PropertiesService.getUserProperties().getProperty('OPENAI_KEY');
  const response = UrlFetchApp.fetch('https://api.openai.com/v1/chat/completions', {
    method: 'post',
    headers: {
      'Authorization': 'Bearer ' + apiKey,
      'Content-Type': 'application/json'
    },
    payload: JSON.stringify({
      model: 'gpt-4o',
      messages: [{ role: 'user', content: prompt }]
    })
  });
  return JSON.parse(response.getContentText()).choices[0].message.content;
}

Now you can type =AI("Write a tagline for a coffee shop") in a cell. It works.

The tradeoffs:

StrengthWeakness
Full control over the API callYou maintain the code forever
No third-party dependenciesNo error handling, retries, or rate limiting in the example above
Free (aside from API costs)Every user needs their own API key set up
No caching, so editing the sheet re-runs every formula
30-second execution limit per custom function
No image generation, vision, or audio support without a lot more code

That 30-second limit is the big one. Complex prompts or slow API responses will time out and return an error. You also need to build your own caching layer. Without it, formulas re-run every time the sheet recalculates. And that happens constantly.

Best for: Developers who want a quick prototype, need a single specific AI call, and are comfortable maintaining Apps Script code.


Option 2: Marketplace add-ons

Add-ons like SheetMagic install from the Google Workspace Marketplace in a few minutes. They give you pre-built custom functions that handle all the infrastructure. API calls, caching, error handling, retries, and rate limiting are all taken care of. You just write formulas.

=AITEXT("Write a tagline for a coffee shop")
=AIIMAGE("Logo for a minimalist coffee brand, flat design")
=GPTV(A2, "What product is shown in this image?")
=AILIST("5 marketing angles for a coffee subscription service")

The tradeoffs:

StrengthWeakness
No code to write or maintainMonthly subscription cost ($20-200/mo)
Works right after you install itToken/credit limits per plan
Built-in caching (results stick around)You depend on the add-on provider
Multiple AI providers (OpenAI, Gemini, Claude, etc.)Less control over raw API settings
Image generation, vision, audio, video, web scraping
BYOK option for power users who want cost control
Handles rate limiting and retries for you

The main cost is the subscription. But think about what you get. The custom function approach means building and maintaining caching, error handling, multi-provider support, and media generation yourself. At any real scale, the engineering time costs more than $20/month.

Note

SheetMagic's free tier includes 20,000 AI tokens and 100 scraping credits. No credit card needed. That's enough to test the text and scraping formulas and see if the add-on approach works for you before paying anything.

Best for: Anyone who wants AI in their spreadsheet without writing or maintaining code. Teams that need multiple AI features (text, images, vision, scraping) in one tool.


Option 3: Direct API integration

Skip the spreadsheet layer entirely. Write a Python script, a Node.js service, or use a platform like Zapier or Make to call AI APIs. Then push results back into Google Sheets through the Sheets API.

import openai
import gspread

client = openai.OpenAI()
gc = gspread.service_account(filename='credentials.json')
sheet = gc.open('My Sheet').sheet1

for i, row in enumerate(sheet.get_all_values()[1:], start=2):
    prompt = f"Write a tagline for: {row[0]}"
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}]
    )
    sheet.update_cell(i, 2, response.choices[0].message.content)

The tradeoffs:

StrengthWeakness
Maximum flexibility and controlLots of setup: API keys, service accounts, auth
No execution time limitsCode lives outside the spreadsheet
Can process thousands of rows in a batchNon-technical team members can't change prompts
Full access to every API parameterNeeds a runtime environment (local machine, server, or cloud function)
Results aren't live. You run the script, then check the sheet

This is the right choice when you're building a production pipeline that happens to output to a spreadsheet. It's way too much when a marketing manager just wants to generate 50 product descriptions and tweak prompts on the fly.

Best for: Engineering teams building automated data pipelines. Cases where the spreadsheet is an output destination, not the workspace.


The comparison

FactorCustom FunctionsAdd-on (SheetMagic)Direct API
Setup time30-60 min3-5 min1-4 hours
MaintenanceYou maintain itProvider maintains itYou maintain it
AI providers1 (whichever you code)6 (OpenAI, Gemini, Claude, etc.)Any you integrate
Text generationYesYesYes
Image generationRequires extra code=AIIMAGE()Requires extra code
Vision/image analysisRequires extra code=GPTV()Requires extra code
Web scrapingNo=VISIT(), =SERP(), etc.Requires extra code
CachingYou build itBuilt-inYou build it
Rate limitingYou build itBuilt-inYou build it
CostAPI usage only$0-200/mo + optional BYOKAPI usage + infrastructure
Non-technical usersNoYesNo

What does each option cost you in time and money?

Put numbers on the example above. The figures are a worked scenario, so swap in your own hourly rate.

  • Custom function. Suppose adding caching, retries and error handling to the snippet in Option 1 takes 6 hours, and your time is worth $50 an hour. That is $300 of build time before the first reliable run, plus whatever an API change costs you later. You pay the AI provider for usage on top.
  • Add-on. SheetMagic's Solo plan is $20 a month for 3,250,000 AI tokens and 10,000 scraping credits. Against the same $300 of build time, that is 15 months of the plan before the do-it-yourself version breaks even, and you never touch the caching code.
  • Direct API. At the 1 to 4 hours of setup in the comparison table above, the same $50 rate is $50 to $200 before the first run. It pays off when the job is a pipeline that runs thousands of rows on a schedule, where nobody needs to edit prompts in the sheet.

The money you do not lose matters too. A custom function without caching re-runs on every recalculation, so you can pay for the same 500 descriptions more than once. Whichever option you choose, check that results are kept once they come back.


Which one should you pick?

Pick custom functions if you're a developer who needs one specific AI call, you enjoy maintaining Apps Script, and you don't need image generation, vision, or web scraping.

Pick an add-on if you want AI in your spreadsheet today, you need more than just text generation, and you'd rather pay $20/month than build and maintain infrastructure.

Pick direct API if the spreadsheet is just an output format for an automated pipeline, you need to process tens of thousands of rows in batch, or you need fine-grained control over every API parameter.

Most people reading this want AI inside their spreadsheet as a working tool. Not as a software engineering project. That's where add-ons win.

Note

Want to see the add-on approach in action? Start with the complete guide to AI in Google Sheets for installation and your first formulas. Then explore specific features: AI image generation, image and document analysis, or AI-powered list extraction.


Have questions about which approach is right for your use case? visit the FAQ.

Text and scraping formulas run on the free allowance. Install from the Google Workspace Marketplace, no card, no expiry.

Install free for Google Sheets

About the author

Phil NguyenPhil builds SheetMagic, the Google Sheets add-on that brings AI and web scraping into the spreadsheet, used by 6,300+ people. He writes these guides from the formulas he runs on his own sheets.