惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
J
Java Code Geeks
博客园 - 聂微东
B
Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
腾讯CDC
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
美团技术团队
博客园 - Franky
Google DeepMind News
Google DeepMind News
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
The Cloudflare Blog

Sanity.io

A Board Game agent built using Sanity Context and Vercel's AI SDK | Sanity Build a prototype with Claude Code that your whole team can edit | Sanity What’s New - May 2026 | Sanity I built a London pub guide with v0 and the Sanity MCP in six hours. Here's what I learned. | Sanity Build a conference concierge with Agent Context and Anthropic | Sanity Build a content-aware Telegram agent with Vercel AI SDK and Chat SDK | Sanity How I used Agent API to generate photos for my family’s recipes | Sanity What’s New April - 2026 | Sanity Better context, better matches: An AI love story (for dogs) | Sanity How to write for an agent | Sanity Content Agent, meet Slack: AI content operations in your workflow | Sanity Structure powers intelligence | Sanity Your agent needs better content. Here's how to give it. | Sanity How to serve content to agents (a field guide) | Sanity Sanity TypeGen GA: Automatic TypeScript types for content and GROQ | Sanity Sanity is now available on the Vercel Marketplace | Sanity The logo soup problem (and how to solve it) | Sanity Content Releases: From scattered updates to coordinated publishing | Sanity What's New - February 2026 | Sanity How we solved the agent memory problem | Sanity v0 Builder Challenge: The winners | Sanity Introducing: Sanity Agent Skills | Sanity Content Agent: Days of work in one conversation | Sanity Our Sanity Values | Sanity Open Source Pledge 2025: Stepping up when it matters | Sanity v0 builder challenge: $3000 in prizes | Sanity Why AI Breaks Without Structured Content Operations | Sanity What’s New January - 2026 | Sanity BFCM 2025: What teams built when infrastructure stopped being the problem | Sanity How AI shaped holiday shopping and what it means for content in 2026 | Sanity
Functions: Life beyond pressing publish | Sanity
Simeon Griggs · 2025-05-15 · via Sanity.io

Sanity Functions is a fully managed serverless environment that lets you create custom content workflows without managing infrastructure.

Automate events that react to content changes. You may validate content, trigger external services, or transform content with AI Agent Actions—all while Sanity handles the scaling, security, and reliability.

Functions integrate seamlessly with your content operations, letting you focus on building what matters to your authors and business.

For everything that happens next

Content is never truly finished, and its life cycle doesn't end when you paste it into a browser and press publish. It may need to be translated to appear in other markets, update a search index, or revalidate a cache to appear on a website at all. These actions directly respond to pressing publish and are the next step in any content lifecycle.

Without Sanity Functions, developers must string together a series of external services that they are responsible for documenting and maintaining. This creates logic related to content that exists outside the rest of your content operations.

This complexity compounds as developers spend more time building infrastructure while authors wait.

Organizations struggle to maintain consistent workflows and reliable content delivery at scale without a unified system for extending content operations.

Co-locating "what happens next" with the rest of your content infrastructure keeps everything organized and streamlined.

Introducing Sanity Functions (and Blueprints!)

Sanity Functions are authored in TypeScript and deployed to the Content Lake. Deploying them requires the first use of the next evolution of Sanity configuration, which we call "Blueprints."

Blueprints represent the best-in-class developer experience for developing and deploying content operations.

The Sanity Content Operating System comprises of deployable infrastructure components for content creation, maintenance, and the post-event lifecycle. It is backed by the Content Lake, a content-optimized, real-time datastore for documents and assets.

The future of Blueprints is infrastructure-as-code to configure all your content operations.

Write, react, repeat

Event-driven workflow

Sanity Functions allow you to respond to changes in your content. When a document is created, updated, or deleted, your function can execute custom logic to maintain data consistency, trigger workflows, or perform automated tasks. This event-driven approach ensures your content stays synchronized and follows business rules in real-time.

Complete context

Sanity Functions can read and write to your dataset, access other documents, and utilize the full Sanity API capabilities. Functions run with the same permissions as your applications, allowing them to perform complex operations while maintaining security. They can query related documents, traverse references, and make informed decisions based on the broader content context.

Extensibility

You can create reusable functions to maintain consistency across your content model and extend functionality across projects. Functions can be packaged as reusable modules and shared between different Sanity projects, making it easier to maintain consistent behavior and reduce code duplication. This modular approach allows you to build a library of tested, reliable functions that can be applied wherever needed.

New: Scheduled Functions

Functions can now run on a recurring schedule, not just in response to content changes. Define a cron expression in your Blueprint to automate nightly syncs, periodic cache invalidation, scheduled notifications, and more. Get started with Scheduled Functions.

Guide: Create, deploy, and test a function

Let's create a Sanity Function that adds the date and time to a "Post" type document the first time it is published.

This guide assumes you have a Sanity Studio with "Post" type documents and a dateTime field named firstPublished. If not, create a new free Sanity Studio project with the command below and choose the "blog" template.

Functions can be initialized with the Sanity CLI. As they are configured and deployed as part of a Blueprint, you'll need to create one of those first.

Create a new Blueprint

Run the following inside of your Sanity Studio project to initialize a new Blueprint:

You should now have two new files:

  • blueprint.json at the root of your project, which contains configuration for the functions you'll create. It deliberately contains no project-specific details such as your Sanity Project ID, so that the configuration is portable between projects.
  • .sanity/blueprint.config.json with project-specific configuration. This file shouldn't be checked into version control.

Create a new function

Run the following to add your first function to the project:

Name the function first-published

You'll now have a functions folder in your project, which are referenced inside the blueprint.json configuration file.

Along with all your other project files, you should now have these in your project:

Update the blueprint.json file to include a filter and projection

  • The filter will ensure the Function only fires on "Post" document types that do not yet have a value in the firstPublished field.
  • The projection will pass along only the _id attribute from the document to the function.

Run the following to test the Function locally using the CLI

You should receive a response like the below:

Take a look in functions/first-published/index.ts to see the code that generated this response.

Add Sanity Client

To patch documents, you'll need to install Sanity Client to the Function's dependencies. We'll also now install a package that contains helper functions to improve the TypeScript support of our function.

Run the following command from inside the first-published folder:

Update the function to create a new client instance using options provided from the handler's context.

Deploying your Blueprint and Function

Run the following command to deploy your Blueprint from the root of your project

In your Studio, create and publish a new "post" type document. Almost immediately after publishing you should see a firstPublished value written to the document.

Sanity Studio dashboard showing title, slug and first published fields
"First published" is a read-only field that has been written to by the Sanity Function

Run the following to view production activity from the first-published function.

You should see logs like below to confirm what you saw in your Sanity Studio.

And that's it! You can now continue to modify your Sanity Function to perform other tasks, add more functions to your project and redeploy the Blueprint at any time.

What will you do with Functions?

Updating documents isn't all you can do to support the content lifecycle with Sanity Functions. Consider what other functionality you could build. Here are some powerful use case ideas:

  • Summarize, tag or embellish content with AI Actions
  • Validate content before proceeding
  • Update documents with new data
  • Trigger external services (CDN, Algolia, Slack)
  • Handle multiple steps in a workflow

Join the discussion

We can't wait to see what you'll wire up with Functions. If you'd love to show it off, tag us on social media or join our community on Discord and post up in the Showcase channel.