Compute and AI

Functions quick start

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.

Delta GROQ CLI tests, Auto update channel for standalone studios and more

v4.9.0

✨ Highlights

Delta GROQ function test command (CLI)

This change enables support for testing with Delta GROQ function. When the event flag is set to update and before and after data is provided via one of the new flags (data-before/after, file-before/after, document-id-before/after), then delta functions in the filter will work as they do in the deployed functions.

Auto update channel for self hosted studios

Adds support for auto update channel configuration for self hosted Studios (i.e. studios not hosted on the *.sanity.studio-domain)

Changes to sanity.cli.ts config

  • Deprecates autoUpdates, replaced with deployment.autoUpdates
  • Deprecates app.id, replaced with deployment.appId.
  • Deprecates studioHost, superseded by deployment.appId.

Other features

  • Schema errors screen now contains a button to copy schema type errors as Markdown.
  • Updated the npx sanity@latest init command in next.js contexts to use next-sanity v11.
  • Fixes popover issues where if you opened a reference within a Portable Text Editor block and attempted to click a field from the opened reference, you would not be able to edit the content.
  • Fixes issue where when working with a PTE fullscreen, adding items that used popover and pressing escape it would close the fullscreen PTE instead of the popover that was opened on top first.

πŸ› Notable bugfixes

  • Fixes an issue where sometimes it was not possible to revert changes to a document.

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.

If you are updating from a version earlier than 3.37.0, you should also check out this article to ensure your dependencies are up to date.

Functions new document change events and filtering options!

v2025-08-20

We are excited to give developers more document change events to trigger their Functions! The new events are:

  • create: Emitted when a document is created.
  • delete: Emitted when a document is deleted.
  • update: Emitted when a document is updated.

Additionally, two new boolean toggles are available when defining the triggering event for your Functions:

  • includeDrafts: Whether the event should be emitted with respect to draft documents. Defaults to false.
  • includeAllVersions: Whether the event should be emitted with respect to version documents (documents part of a Content Release). Defaults to false.

Keep in mind that combining update with includeDrafts and/or includeAllVersions may result in many, rapid, invocations whenever changes are synced. See the rate limits and use with caution.

Note that these new events and options have significant overlap with the existing publish event. In fact, publish can be defined as:

  • on: ['create', 'update'], and
  • includeAllVersions: true

The publish event was an early beta attempt at encapsulating a useful, initial first-pass at a Functions source event.

These new additions set up a deprecation of the publish event, so keep an eye out for that to officially land sometime in the near future. If you want to get ahead of things, you can update any existing function events that use on: ['publish'] to instead use the on and includeAllVersions values mentioned aboveβ€”or make them more specific for your needs.

Support for these new events and filters landed in the following tools under the specified versions. Upgrade to at least these versions to take advantage of the changes:

Functions `projection` breaking change

v2025-08-06

Why we're making the change

⚠️ Previously, we accepted GROQ projections in function event definitions that were not wrapped in curly braces ({}). Behind the scenes, we would transparently wrap your projection with curly braces.

πŸ“£ In order to better support the full GROQ specification, as of now, if you wish to receive an object as a projection in your function invocation, you are required to wrap your projection in curly braces.

Before

❌ Previously, you could provide the following projection that expressed "give me an object with _id and type properties":

{
  "on": ["publish"],
  "filter": "_type == 'post'",
  "projection": "_id, type"
}

Now, trying to create or update a function with the above projection will yield an error like:

Failed to manage function subscription: Failed to validate document change event rule: projection is invalid: parse error at position 3: unable to parse entire expression"

After

βœ… Instead, wrap the projection with curly braces:

{
  "on": ["publish"],
  "filter": "_type == 'post'",
  "projection": "{_id, type}"
}

This explicitly says that you want an object.

Existing functions

If you have an existing function deployed to Sanity, we've migrated the deployed code to the new syntax. Your function will continue to work as it has without any intervention.

Prior to your next deployment, you will need to update any projections to use the new syntax. In short, wrap your projection in curly braces as shown above and then deploy the changes.

Functions now supports full GROQ syntax

v2025-07-29

Up until now, customers using GROQ to limit the scope of Function invocations did not have access to the full suite of GROQ functions and features. Powerful abilities like Delta functions or document dereferences were unfortunately not supported in the initial release of Functions, and if you tried to deploy a Function using either of these features (among others), you would see an error during your Blueprint deployment.

However, that is no longer the case! You can now use the full power of GROQ with Functions.

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.