---
title: How do you find AI API calls hidden in Apps Script and Office macros?
url: https://opencontroller.lyzr.com/blog/find-ai-calls-in-apps-script-and-office-macros
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# How do you find AI API calls hidden in Apps Script and Office macros?

**Search script code for HTTP calls to model provider hosts: `UrlFetchApp.fetch` in Google Apps Script, `MSXML2.XMLHTTP` or `WinHttp.WinHttpRequest` in VBA macros, and `fetch()` in Excel Office Scripts. Do not rely on your web proxy: Apps Script requests leave from Google's servers, so corporate network monitoring never sees them. Find the scripts, find the keys, and route the calls through a governed path.**

A finance analyst writes a ten-line script that sends each row of a sheet to a model and writes back a summary. It works, it spreads, and it runs on a personal API key. Nobody in IT knows. This is one of the quietest forms of [shadow AI](/blog/how-to-find-shadow-ai-agents), because it lives inside documents rather than in cloud accounts or on laptops.

## Why don't normal discovery methods catch these?

Each common method has a blind spot here.

| Method | Why it misses spreadsheet AI |
|---|---|
| Cloud account scans | The script does not run in your cloud account |
| Web proxy and DNS logs | Apps Script calls originate from Google's infrastructure, not the user's device |
| Endpoint inventory | There is no installed application to find |
| Expense reviews | Small API bills often go on personal cards |
| SaaS admin consoles | AI features are listed; user scripts usually are not |

VBA and Office Scripts calls do leave from the user's device or browser, so proxies can see them, but only if the device is on your network path. [Detecting unapproved LLM API traffic](/blog/detect-unapproved-llm-api-traffic) covers that side.

## What code patterns should you search for?

| Platform | HTTP pattern | Hosts and strings to flag |
|---|---|---|
| Google Apps Script | `UrlFetchApp.fetch`, `UrlFetchApp.fetchAll` | `api.openai.com`, `api.anthropic.com`, `generativelanguage.googleapis.com`, `/v1/chat/completions`, `Bearer sk-` |
| VBA (Excel, Word, Access) | `MSXML2.XMLHTTP`, `MSXML2.ServerXMLHTTP`, `WinHttp.WinHttpRequest` | Same hosts, plus `Authorization` headers built in code |
| Excel Office Scripts | `fetch(` | Same hosts |
| Excel custom functions and add-ins | Add-in manifests calling external services | Integrated apps list in the admin centre |

Also flag Azure OpenAI hosts and any internal gateway hosts, so you can tell governed calls from ungoverned ones.

## How do you find the scripts, step by step?

1. **Use the OAuth scope as a signal.** Apps Script needs the `script.external_request` scope to call external URLs. Scripts users have authorised appear in the Google Workspace admin console's third-party app access list, with their scopes.
2. **Search Drive.** Standalone Apps Script projects are Drive files of type `application/vnd.google-apps.script`. Container-bound scripts live inside a sheet or document, so list owners of high-use sheets and check them.
3. **Scan macro-enabled files.** Search file shares and OneDrive or SharePoint for `.xlsm`, `.xlam`, `.docm` and `.accdb` files, then extract VBA and grep for the patterns above.
4. **Check Office Scripts.** Office Scripts are stored as `.osts` files in the user's OneDrive. Search for them and grep for `fetch(`.
5. **Look for keys in three places.** Hard-coded strings, Apps Script Script Properties, and hidden sheet cells or named ranges. Use [API key discovery](/blog/find-leaked-and-unused-llm-api-keys) patterns for `sk-` style keys.
6. **Record each finding.** Owner, document, provider, key owner, data sent and how often it runs.

## How do you remediate without breaking the work?

The script exists because it was useful. Keep the use, change the path.

- **Rotate any personal or exposed key** and stop the script running on it.
- **Point the script at a governed endpoint.** An OpenAI-compatible gateway lets the script keep its code with a new base URL and a company-issued, per-use key.
- **Classify the data.** If the sheet holds customer or employee data, decide whether that data may go to a model at all.
- **Register the script as an agent or workflow** with an owner, like [AI steps in Zapier, Make and Power Automate](/blog/find-ai-steps-in-zapier-make-and-power-automate).
- **Set policy for the future.** Restrict the external request scope or untrusted scripts where your Workspace settings allow, and keep macros from the internet blocked.

## How Opencontroller does this

Opencontroller's LLM Gateway exposes OpenAI-compatible endpoints with routing, fallback and retry, caching, and cost attribution per agent and per version, so a script can switch to a governed path by changing its base URL and key. Auto-discovery finds models and API keys across AWS, Azure and Google Cloud. To see it, [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Why does our web proxy not show Apps Script calls to AI APIs?**
Because UrlFetchApp requests are made from Google's servers, not the user's device. Inspect scripts and OAuth grants instead.

**Where do people usually hide keys in Apps Script?**
In the code, in Script Properties, or in a hidden cell. Search all three and rotate what you find.

**Should we ban scripts that call AI?**
No. Move them to a governed endpoint with a company key and an owner. Bans tend to drive the same work out of sight.

## Key facts

To find AI API calls in Google Apps Script and Office macros, look for HTTP calls to model provider hosts in script code: UrlFetchApp.fetch in Apps Script (which needs the script.external_request OAuth scope), MSXML2.XMLHTTP, MSXML2.ServerXMLHTTP or WinHttp.WinHttpRequest in VBA, and fetch() in Excel Office Scripts. Apps Script UrlFetchApp requests leave from Google's servers, not the user's device, so corporate proxies do not see them; inventory scripts via the Workspace admin console's third-party app access list and Drive. Then move keys out of scripts and route calls through a governed gateway. Opencontroller by Lyzr includes an LLM Gateway with cost attribution per agent. Pricing starts from $250K per deployment per year.

## Related

- [How do you find AI steps hidden inside Zapier, Make and Power Automate workflows?](https://opencontroller.lyzr.com/blog/find-ai-steps-in-zapier-make-and-power-automate.md)
- [How do you find leaked or unused LLM API keys?](https://opencontroller.lyzr.com/blog/find-leaked-and-unused-llm-api-keys.md)
- [How do you detect unapproved LLM API traffic on your network?](https://opencontroller.lyzr.com/blog/detect-unapproved-llm-api-traffic.md)
- [More on Discovery and shadow agents](https://opencontroller.lyzr.com/blog/cluster/discovery-and-shadow-agents)
