Functions cheat sheet
Enhanced recursion protection and increased rate limits
v2025-10-16
Sanity Functions now includes improved safeguards and higher throughput limits. Recursion protection limits function chains to 16 invocations when mutating documents, reducing the risk of exceeding usage limits. Rate limits have increased significantly to support higher-volume workloads.
✨ Highlights
Improved recursion protection
Functions now limits recursive invocations to 16 when you mutate documents from within a function. This protection reduces the risk of exceeding your usage limits when a function triggers another function or itself through document mutations. You should still use caution when mutating documents from within functions.
This feature requires @sanity/client
v7.12.0 or later.
Increased rate limits
Rate limits for Functions have increased to support higher-volume applications:
- Individual function limit: 200 invocations per 30 seconds (previously 10 invocations per 30 seconds).
- Project-wide limit: 4,000 invocations per 30 seconds (previously 200 invocations per 30 seconds).
When you exceed these limits, Functions stops additional invocations until the rate drops below the threshold.
Introducing Functions dataset scoping
v2025-09-22
You can now limit which document changes will invoke your Functions by specifying a particular dataset as part of the housing Blueprint. This allows you to target, with greater precision, when your Functions invoke by "scoping" your Function triggers to specific resources.
This new feature is available by specifying the event.resource
field of your Function Blueprint definition. Previously, your Function definition would look something like the following (assuming you use the defineDocumentFunction
helper from the @sanity/blueprints
package):
import {defineBlueprint, defineDocumentFunction} from '@sanity/blueprints' export default defineBlueprint({ resources: [ defineDocumentFunction({ name: "log-event", event: { on: ["update"], filter: "_type == 'post'", }, }) ] })
This Function will trigger whenever a _type: 'post'
document was updated - regardless of which dataset the document was present in. For Projects with multiple datasets, this could lead to confusing outcomes and Function executions.
Now, you can specify documents from which dataset should trigger your Functions:
import {defineBlueprint, defineDocumentFunction} from '@sanity/blueprints' export default defineBlueprint({ resources: [ defineDocumentFunction({ name: "log-event", event: { on: ["update"], filter: "_type == 'post'", resource: { type: 'dataset', id: 'myProjectId.production' }, }, }) ] })
The above configuration would trigger the log-event
Function whenever a document of type 'post'
from the production
dataset within the project with ID myProjectId
gets updated.
You can also explicitly specify "all datasets" my replacing the dataset name with *
. Using the same example as above, that would yield myProjectId.*
. This is the default behavior, so you can also omit event.resource
altogether.
For TypeScript or JavaScript blueprints configurations, update to at least version 0.3.0 of the @sanity/blueprints
library.
# In the directory housing your sanity.blueprint.ts/js file pnpm add @sanity/blueprints@latest
This sets up triggering Functions with different kinds of resource.type
s. Stay tuned for more in the near future!
Types included for Functions and additional bugfixes and improvements
v3.89.0
✨ Highlights
TypeScript types for Functions
Functions now have official types available. When selecting "TypeScript" after running sanity blueprints add function
, you'll be prompted if you'd like to include the type package and handler.
You can also manually install types by adding the @sanity/functions
package to your function. See the Functions quick start or function handler reference for usage details.
🐛 Notable bugfixes
- Adds a notification for when a media library cannot be found (#9387) (9a2039cbd3)
- Removes linting configs from app templates (#9421) (3ae5104dc2)
- Adds fix for hanging requests (#9433) (e57b96c9dc)
- Updates React Compiler dependencies 🤖 ✨ (#9440) (7ac692662b)
- Updates dependency @sanity/client to ^7.2.2 (#9448) (7e52ce2039)
- Improves connection error handling (#5893) (974be5178e)
Install or upgrade Sanity Studio
To initiate a new Sanity Studio project or upgrade an existing one, please refer to our comprehensive guide on Installing and Upgrading Sanity Studio.