For Agents
List and invoke Sanity Functions with a test event, read or stream their logs, and set or remove their environment variables.
Use for: Invoke my Sanity function with this test document and wait for the result, List all functions in project 24s6f8sr that failed to update, Show the logs for the last execution of this function, I need to set the OPENAI_KEY environment variable on a Sanity function
Not supported: Does not create, deploy, or delete functions, and does not edit content. Use for invoking existing Sanity Functions and managing their logs and environment variables only.
The Sanity Functions API runs and inspects the serverless functions deployed to a Sanity project or organization. It lists functions with filters for region (us-east-1 or eu-central-1) and status, reads one function's definition, which can be a document, media library asset, cron, queue, pub/sub, durable, or sync-tag-invalidate function, and invokes it with an event payload, synchronously or not. It also reads and streams a function's logs, deletes them, and sets or removes environment variables by key. Every call names its project or organization in the x-sanity-scope-id and x-sanity-scope-type headers.
Install Jentic One Beta
Jentic One is a self-hosted execution layer for AI agents. It lets your agent call the Functions API, or any other public or private API you need. You set the rules, the agent never sees your credentials, and every call is logged.
Two steps, two machines. Install the instance in a safe environment, then register your agent from wherever it runs.
Step 1: Jentic One Host machine
# On the machine that will host your Jentic One instance:
curl -fsSL "https://jentic.com/install.sh?src=apis&api=%2Fapis%2Fsanity.io%2Fsanity-functions-api" | shStep 2: Agent machine
# On the machine where your agent runs (keep this separate from the instance):
curl -fsSL "https://jentic.com/install.sh?src=apis&api=%2Fapis%2Fsanity.io%2Fsanity-functions-api" | sh
jentic register # connects your agent to your Jentic One instanceJentic One is in public beta. The setup above keeps your agent separate from the instance, which is what you want before using real credentials: an agent running as the same OS user as Jentic One can read its stored keys directly. Just evaluating? A single local install is fine to start. See the secure deployment guide for the tiers.
What an agent can do with Functions API.
List the functions in a Sanity project or organization, filtered by region such as us-east-1 or eu-central-1 and by status such as assigned or failed-update
Read one function's definition, including its type such as sanity.function.document or sanity.function.cron
Invoke a function with an event whose data object is the test payload, choosing synchronous execution with the sync query parameter
Page through a function's logs with limit and offset, narrowed to one executionId
Stream new log entries as server-sent events from the logs stream endpoint, resuming after a given point with the after parameter
List a function's environment variable keys, set one by envVarKey with a value, or delete it
Patterns agents use Functions API for, with concrete tasks.
★ AI agent debugging a Sanity Function
An agent asked why a document-triggered function misbehaves searches Jentic for 'invoke a Sanity function', loads the invoke operation, and posts a test event with sync set to true so it gets the result back. It then reads the function's logs filtered by executionId to see what happened in that run, and does it all without the Sanity token entering its context.
POST /{apiV}/functions/{functionId}/invoke with sync=true, headers x-sanity-scope-id 24s6f8sr and x-sanity-scope-type project, and body {event: {data: {_id: 'post-1', title: 'Test'}}}, then GET /{apiV}/functions/{functionId}/logs and report the entries for that run
Managing function configuration
Functions that call outside services need keys and settings. The environment variables endpoints list a function's variable keys without their values, set a value by envVarKey with a PUT whose body holds the value, and delete a key that is no longer needed, so configuration can change without redeploying the function code.
GET /{apiV}/functions/{functionId}/envvars to list keys, then PUT /{apiV}/functions/{functionId}/envvars/{envVarKey} with envVarKey WEBHOOK_URL and body {value: 'https://hooks.example.com/sanity'}
Monitoring function health across a project
Teams with many functions need to spot the broken ones. The list endpoint filters by status values such as failed-create, failed-update, or disabled and by region, and each function's logs can be paged with limit and offset or tailed live as server-sent events from the stream endpoint.
GET /{apiV}/functions with status failed-update for project 24s6f8sr, then GET /{apiV}/functions/{functionId}/logs with limit 20 for each one returned
9 endpoints — the sanity functions api runs and inspects the serverless functions deployed to a sanity project or organization.
METHOD
PATH
DESCRIPTION
/{apiV}/functions
List functions
/{apiV}/functions/{functionId}
Read a function
/{apiV}/functions/{functionId}/invoke
Invoke a function with an event
/{apiV}/functions/{functionId}/logs
Retrieve function logs
/{apiV}/functions/{functionId}/logs/stream
Stream function logs
/{apiV}/functions/{functionId}/envvars/{envVarKey}
Set an environment variable
/{apiV}/functions
List functions
/{apiV}/functions/{functionId}
Read a function
/{apiV}/functions/{functionId}/invoke
Invoke a function with an event
/{apiV}/functions/{functionId}/logs
Retrieve function logs
/{apiV}/functions/{functionId}/logs/stream
Stream function logs
/{apiV}/functions/{functionId}/envvars/{envVarKey}
Set an environment variable
This API is usable in Jentic One now. Its AI-readiness score against Jentic's framework shows where it stands today and where improvements would make it even easier for agents to use.
Base layer of spec validity and structural soundness.
Aggregated quality score from linter diagnostics, weighted by severity.
Percentage of `$ref` references that resolve successfully.
Checks whether the API description parses successfully and conforms to its declared specification (e.g., OpenAPI).
Structural correctness score based on schema issues using logarithmic dampening.
Clarity, completeness, and ingestion readiness for developers and tooling.
How richly the API is illustrated with examples.
Percentage of examples that conform to their schemas.
Percentage of operations with complete response definitions (success, client error, server error).
Health of API ingestion, bundling, and resolution within Jentic pipelines.
Semantic breadth, depth, and agent comprehension for AI systems.
Coverage of descriptions across API elements.
Coverage of RFC 9457 Problem Details for error responses.
Coverage, uniqueness, and casing consistency of operationIds for AI inference.
Coverage of summaries across operations/tags/info.
Functional utility, complexity comfort, and AI orchestration readiness.
Agent comfort level based on API operational and structural complexity.
Trust, risk posture, and security compliance.
Average quality of security schemes based on authentication method strength (weakest link for OAuth2).
Findability, semantic richness, and reasoning readiness.
Clarity and depth of descriptions across API elements.
Score it yourself
Every API in the directory is allowlisted, so you can re-score it with no key required.
npx @jentic/api-scorecard-cli score <openapi-url>What agents get from Jentic-routed access to this vendor.
Setup
Wiring the Sanity Functions API by hand means sending a bearer token plus the x-sanity-scope-id and x-sanity-scope-type headers on every call, shaping the event body for invoke, and consuming server-sent events for the log stream. Through Jentic you install once, import it from the API Directory, store the token once, and your agent calls it.
Permission scoping
Sanity puts the function id in the URL path (/{apiV}/functions/{functionId}/...), so a rule can pin your agent to one function and the operations you pick. The project itself travels in the scope headers, so rules bound which functions and operations the agent may call, not which project, and destructive ones like log deletion or environment variable removal are not included unless you add them.
Credential isolation
Your Sanity token is stored once, encrypted, by your own Jentic One instance and injected at execution time. It never enters the agent's prompt, logs, or context.
Intent-based discovery
Agents search Jentic by intent such as 'invoke a Sanity function' or 'stream Sanity function logs', and Jentic returns the matching operation with its input schema, including the required scope headers, so the agent calls it correctly first time.
Alternatives and complements available in the Jentic catalogue.
Specific to using Functions API through Jentic.
What authentication does the Sanity Functions API use?
Per its OpenAPI spec, every operation uses a bearer token, described as a Sanity API session token, in the Authorization header. Each call also needs the x-sanity-scope-id and x-sanity-scope-type headers to name the project or organization the function belongs to. Through Jentic the token is stored by your own instance and attached at call time.
How do I invoke a Sanity Function for testing?
POST to /{apiV}/functions/{functionId}/invoke with a body of the form {event: {data: {...}}}, where data is the payload the function should receive. Set the sync query parameter to true to run it synchronously; it defaults to false. The optional x-sanity-lineage header carries a lineage token for the request.
Can I deploy or create functions with the Sanity Functions API?
Not through this spec. It covers listing, reading, invoking, logs, and environment variables for functions that already exist; there is no create, deploy, or delete-function operation in it.
What are the rate limits for the Sanity Functions API?
The OpenAPI spec does not specify rate limits. Check the Sanity documentation at https://www.sanity.io/docs for current limits on functions for your plan.
Is there a Sanity Functions MCP server?
You don't need an MCP server to give your agent the Sanity Functions API. Jentic connects it directly from the API Directory: import it, store your Sanity token once, and your agent calls the invoke, logs, and environment variable operations it needs without loading a separate server's tool definitions.
How do I read a function's logs through Jentic?
Search Jentic for 'get Sanity function logs', load the matching operation, and execute GET /{apiV}/functions/{functionId}/logs with the scope headers, adding executionId to narrow it to one run. It returns the most recent entries by default, and limit and offset page further back. To run it on your own infrastructure, install Jentic One from its GitHub repo.
Can I limit what my agent is allowed to do with the Sanity Functions API?
Yes. Allow only the invoke and log-read operations under /{apiV}/functions/abcd123456, and the agent can test that one function and read its output while environment variable changes and log deletion stay off its list. Every call it makes is logged.
GET STARTED