How Sanity Functions work
Blueprints manage Sanity resources as infrastructure as code, from a sanity.blueprint.ts file kept in the repository. In that file, a GROQ filter in each function's event configuration limits which documents trigger it. A GROQ projection shapes the data passed to the function and has no effect on what triggers it.
Each function's index file exports a handler, which receives a context and an event. Deployed functions run on Node.js v24.x, and Sanity recommends the same version for local work. The sanity functions dev command opens a local playground for testing a function before you deploy it. Sanity documents the setup in its introduction to Functions. For the CMS basics, read what Sanity is.
Function types and limits
Each function type has a different trigger.
Document functions (
sanity.function.document) fire on document changes in a project dataset.Media Library Asset functions react to asset changes in Media Library and only cover the
sanity.assetdocument type.Sync tag invalidate functions react to Live Content changes through sync tags.
PubSub functions are called by other functions. Content events do not trigger them.
Scheduled functions, defined with
defineScheduledFunction, run on a cron expression or an explicit schedule object instead of a document event.
Functions time out after 10 seconds by default, and the blueprint can raise this. Cost is based on invocations, memory and duration; memory defaults to 1 GB and can be raised to 10 GB per function. Requests a function makes to the Content Lake still count toward the project's API request quotas. To stop runaway loops, Sanity halts a chain of function-triggered invocations once it reaches a depth of 16.
Built-in serverless code is one point to weigh in Sanity vs Contentful. Project help is available through Pagepro's Sanity development services.
Sources
- FunctionsSanity · sanity.io
- Blueprints introductionSanity · sanity.io
- Create a Document FunctionSanity · sanity.io
- Functions v2026-05-07: Introducing Scheduled FunctionsSanity · sanity.io