
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeUnfortunately, Sanity doesn't currently provide a built-in way to create custom HTTP API endpoints directly within the Sanity platform (like Next.js's /pages/api/my-endpoint.js).
Here's what's actually available and what you'll need to do:
Sanity Functions are event-driven, not HTTP endpoints. They're triggered by document changes (create, update, delete events) and run automatically in response to those events. You can't call them directly via a URL from Studio components.
Webhooks work in the opposite direction - they send HTTP requests OUT to external services when content changes occur. They don't receive incoming HTTP calls.
For a "send an email" component in Studio that needs server-side execution, you'll need to:
Keep your Next.js API routes as the backend for Studio actions:
// In your Studio component
const handleSendEmail = async () => {
await fetch('https://your-nextjs-app.com/api/send-email', {
method: 'POST',
body: JSON.stringify({to, subject, body})
})
}This is actually a solid pattern - your Next.js app provides the API infrastructure while Studio provides the UI.
Use services like:
Then call those endpoints from your Studio component.
If your use case fits an event-driven model (e.g., "send email when document is published"), you could:
This is more indirect but keeps everything within Sanity's infrastructure.
Sanity is positioning itself as a "Content Operating System" where Sanity Functions handle content lifecycle automation, while external services handle general-purpose HTTP endpoints. The platform is optimized for content operations rather than general API hosting.
For your specific use case, sticking with Next.js API routes is perfectly valid and actually quite common in the Sanity community!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store