Apps Script: Service invoked too many times in a short time
Last verified
Exception: Service invoked too many times in a short time: Calendar. Try Utilities.sleep(1000) between calls.What it means
This is a rate limit, not a daily limit. Google's quotas page says it indicates that the script called the given service too many times in a short period, and the message itself suggests pausing between calls. The service name varies with what you were calling.
Your daily quota may be nowhere near exhausted. Spacing the same calls out over time is usually enough to make them succeed.
It commonly appears in tight loops that create calendar events, send mail, or modify many Drive files back to back, and in custom functions that run in many cells at once.
What it looks like
for (const ev of events) {
cal.createEvent(ev.title, ev.start, ev.end);
Utilities.sleep(1000);
}Why it happens
- A loop calling the same service hundreds of times with no pause.
- A custom function used in many cells, all recalculating simultaneously.
- Several triggers firing at the same moment and hitting the same service.
- Retry logic that retries immediately rather than backing off.
How to fix it
- Add Utilities.sleep between calls in the loop, as the message suggests, starting around 1000 ms.
- Wrap calls in retry with exponential backoff: wait 1, 2, 4, 8 seconds between attempts and stop after a few tries.
- Use batch-capable methods where available instead of one call per item.
- For custom functions, accept a range and return a 2D array so the function runs once instead of once per cell.
- Stagger triggers so they do not all fire on the same minute.
How to stop it recurring
Write service calls with rate in mind from the start: batch where possible, pause in loops, and centralize retries in one helper with backoff. For custom functions, design them to take ranges, which Google itself recommends to avoid repeated invocations.
Official documentation: developers.google.com/apps-script/guides/services/quotas. See all Apps Script error messages or the Apps Script limits and quotas.
Related errors
- Service invoked too many times for one dayException: Service invoked too many times for one day: urlfetch.
- Too many simultaneous invocations: SpreadsheetsException: Too many simultaneous invocations: Spreadsheets
- Too many scripts running simultaneously for this Google user accountThere are too many scripts running simultaneously for this Google user account.
Definitions
- Google Apps ScriptGoogle Apps Script is Google's cloud-hosted JavaScript platform for automating Google Workspace: Sheets, Gmail
- Error HandlingError handling is the practice of anticipating, detecting, and responding to errors in software execution, inc
- Rate LimitingRate limiting is a technique that controls the number of requests a client can make to a server within a given
- OAuth 2.0OAuth 2.0 is the IETF authorization standard (RFC 6749) that lets an app access your account in another servic
Quick answers
What does "Service invoked too many times in a short time" mean in Apps Script?
This is a rate limit, not a daily limit. Google's quotas page says it indicates that the script called the given service too many times in a short period, and the message itself suggests pausing between calls. The service name varies with what you were calling. Your daily quota may be nowhere near exhausted. Spacing the same calls out over time is usually enough to make them succeed.
How do I fix "Service invoked too many times in a short time"?
1. Add Utilities.sleep between calls in the loop, as the message suggests, starting around 1000 ms. 2. Wrap calls in retry with exponential backoff: wait 1, 2, 4, 8 seconds between attempts and stop after a few tries. 3. Use batch-capable methods where available instead of one call per item. 4. For custom functions, accept a range and return a 2D array so the function runs once instead of once per cell. 5. Stagger triggers so they do not all fire on the same minute.
Run the job somewhere with its own limits
If a script keeps hitting its host's quotas, an Autonoly workflow can run the same steps on a schedule in an isolated cloud container, and the AI agent has a terminal with Python for steps that need code. Autonoly has limits of its own, priced in credits.
Also see Agent terminal & SSH.