Agent Actions
Reference documentation for the Agent Actions HTTP API.
The Agent Actions API gives you full access to Agent Actions through an HTTP endpoint instead of the Sanity client. We highly suggest using this only in situations where you cannot otherwise use the client.
Experimental feature
Agent Actions are experimental, and the API may change at any time. This API requires using vX for the API version.
Authentication
All requests must be authenticated.
Base API server URL
Parameterized base URL
https://{projectId}.api.sanity.io/{apiVersion}/agent/actionVariables
- projectIdstringdefault:
"your-project-id"Sanity project ID
- apiVersionstringdefault:
"vX"API version
Endpoints
Send an instruction to Generate
/generate/{dataset}Sends an instruction request to Generate for a specific dataset.
Examples and implementation details can be found in the Generate documentation.
Path parameters
Request body application/json
The schema identifier reported by
sanity deployorsanity schema deploy.Example:_.schemas.default- conditionalPathsobject
Allows the instruction to modify conditional
readOnlyorhiddenfields. Does not apply to fields explicitly set as hidden or readOnly in the schema.Show child attributes
When false, forces all conditional readOnly fields to be writable.
- booleandefault:
trueWhen false, forces all conditional hidden fields to be writable.
- pathsarray
Override the default behavior of individual conditional paths.
Set to true to mutate published documents. By default, Agent Actions will never mutate a published document. They will use a draftId if a publishedId is provided. Operations on drafts receive initial state from the published document, if no draft exists. If a draft exists, it is used as the initial state. The returned
_idwill be that of the modified document.Documents set to
liveEdit: truewill be mutated as ifforcePublishedWrite: true.When true, documents aren't created or mutated.
When true, requests occur in the background. True is incompatible with
noWrite: true.- temperaturenumber
Controls the level of variance in the response. A higher value returns more variation in responses, while a lower value returns more predictable responses. Defaults to
0.3for Generate, and0for Transform and Translate.Example:0.7 - localeSettingsobject
When provided with locale settings, Agent Actions write to
dateanddatetimefields. Otherwise, those fields are ignored.Example{"locale":"en-US","timeZone":"America/New_York"}Show child attributes
A valid Unicode BCP 47 locale identifier. This will affect how natural language time and date phrases are parsed and presented.
Example:en-USA valid IANA time zone identifier. This will ensure dates and times are interpreted correctly relative to the user's local time.
Example:America/New_York
Describes the instruction. Reference
instructionParamsusing the$variablesyntax.Example:Create a new document with a title like $title, that matches the style of $externalTitle, and generate content based on the $backgroundContext.- instructionParamsobject
Parameter values available to reference in the instruction.
There are four types of parameters:
constant: Set a static value. Ex:paramName: { type: 'constant', value: 'New title'}, or the shorthandparamName: 'New title'field: Target a field in the document to set the parameter to its value. Also takes an optionaldocumentIdto target a field in a different document. Ex:paramName: { type: 'field', path: 'poster'}groq: Set the parameter to the result of a GROQ query. Ex:paramName: { type: 'groq', query: '*[_type == $docType]', params: { 'docType': 'article'} }document: Set the parameter to the value of the entire document. If nodocumentIdis provided, the current document is returned. Prompt requests requiredocumentIdforfieldanddocumentparameters. Ex:paramName: { type: 'document', documentId: '123'}
Defines which parts of the document will be affected by the Generate instruction.
Show child attributes
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }] Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncateditems
Further fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncateditems
Further fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
Further fields truncatedFurther fields truncated- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncatedThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
Further fields truncatedFurther fields truncatedSets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
Further fields truncatedFurther fields truncated
items
Set to the document ID of the document you want to modify. This is the shorthand equivalent of
targetDocument: { _id: '123', operation: 'edit' }. Mutually exclusive withtargetDocument.
The schema identifier reported by
sanity deployorsanity schema deploy.Example:_.schemas.default- conditionalPathsobject
Allows the instruction to modify conditional
readOnlyorhiddenfields. Does not apply to fields explicitly set as hidden or readOnly in the schema.Show child attributes
When false, forces all conditional readOnly fields to be writable.
- booleandefault:
trueWhen false, forces all conditional hidden fields to be writable.
- pathsarray
Override the default behavior of individual conditional paths.
Set to true to mutate published documents. By default, Agent Actions will never mutate a published document. They will use a draftId if a publishedId is provided. Operations on drafts receive initial state from the published document, if no draft exists. If a draft exists, it is used as the initial state. The returned
_idwill be that of the modified document.Documents set to
liveEdit: truewill be mutated as ifforcePublishedWrite: true.When true, documents aren't created or mutated.
When true, requests occur in the background. True is incompatible with
noWrite: true.- temperaturenumber
Controls the level of variance in the response. A higher value returns more variation in responses, while a lower value returns more predictable responses. Defaults to
0.3for Generate, and0for Transform and Translate.Example:0.7 - localeSettingsobject
When provided with locale settings, Agent Actions write to
dateanddatetimefields. Otherwise, those fields are ignored.Example{"locale":"en-US","timeZone":"America/New_York"}Show child attributes
A valid Unicode BCP 47 locale identifier. This will affect how natural language time and date phrases are parsed and presented.
Example:en-USA valid IANA time zone identifier. This will ensure dates and times are interpreted correctly relative to the user's local time.
Example:America/New_York
Describes the instruction. Reference
instructionParamsusing the$variablesyntax.Example:Create a new document with a title like $title, that matches the style of $externalTitle, and generate content based on the $backgroundContext.- instructionParamsobject
Parameter values available to reference in the instruction.
There are four types of parameters:
constant: Set a static value. Ex:paramName: { type: 'constant', value: 'New title'}, or the shorthandparamName: 'New title'field: Target a field in the document to set the parameter to its value. Also takes an optionaldocumentIdto target a field in a different document. Ex:paramName: { type: 'field', path: 'poster'}groq: Set the parameter to the result of a GROQ query. Ex:paramName: { type: 'groq', query: '*[_type == $docType]', params: { 'docType': 'article'} }document: Set the parameter to the value of the entire document. If nodocumentIdis provided, the current document is returned. Prompt requests requiredocumentIdforfieldanddocumentparameters. Ex:paramName: { type: 'document', documentId: '123'}
Defines which parts of the document will be affected by the Generate instruction.
Show child attributes
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }] Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncateditems
Further fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncateditems
Further fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
Further fields truncatedFurther fields truncated- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncatedThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Sets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
Further fields truncatedFurther fields truncatedSets the default operation for all paths in the target.
Operation types:
- 'set': Overwrites and replaces the full field value.
- 'append':
- array fields: Appends new items to the end of the array.
- string fields: Appends new content to the end of the string.
- text fields: Appends new content to a new line after the existing content.
- number fields: The sum of the new value and the existing value.
- Other field types not mentioned will use
setinstead.
- 'mixed': (Default) Sets non-array fields, and appends array fields.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
- includearray
Show child attributes
items
Further fields truncatedFurther fields truncated
items
- targetDocumentrequired
The operation to perform and the target document to transform.
Show child attributes
- _idstring
The document type to create.
- initialValuesobject
Define any initial values for the document. Similar to initial value templates in Studio, this is useful for setting fields to pre-determined values directly without going through the LLM.
Example{"author":{"_ref":"abc123456","_type":"reference"}}
The document type to create.
- initialValuesobject
Define any initial values for the document. Similar to initial value templates in Studio, this is useful for setting fields to pre-determined values directly without going through the LLM.
Example{"author":{"_ref":"abc123456","_type":"reference"}}
The document type to create.
- initialValuesobject
Define any initial values for the document. Similar to initial value templates in Studio, this is useful for setting fields to pre-determined values directly without going through the LLM.
Example{"author":{"_ref":"abc123456","_type":"reference"}}
Responses
Request was successful, returning the resulting document.
The ID of the document.
Example:123The type of the document.
Example:articleThe creation date of the document.
Example:2025-03-12T19:28:18ZThe last update date of the document.
Example:2025-03-12T19:28:18Z- _revstring
The revision number of the document.
Example:rev123
Request accepted and processed asynchronously (async: true). Returns the ID of the document that will be modified.
- _idstring
The ID of the document.
application/json{
"_id": "drafts.123"
}Bad request. The request body is invalid, contains incompatible parameters, or uses an API version other than vX.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"statusCode": 400,
"message": "Invalid request body",
"statusMessage": "Bad Request",
"error": "Validation error: Required at \"schemaId\"",
"details": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"schemaId"
],
"message": "Required"
}
]
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Incompatible parameters: async and noWrite cannot both be true"
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Agent Actions are only available on apiVersion vX"
}Unauthorized. The token is missing, invalid, or expired.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Unauthorized",
"statusCode": 401,
"message": "Session expired"
}Forbidden. AI features are disabled for the project's organization.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "AI features have been disabled at this organization's request.",
"statusCode": 403,
"message": "Feature disabled.",
"organization": {
"id": "oABC123",
"name": "Example organization"
}
}Not Found. The document or the schema could not be found.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Not Found",
"statusCode": 404,
"message": "No document exists for id: \"123\""
}{
"error": "Not Found",
"statusCode": 404,
"message": "Schema for schemaId '_.schemas.default' could not be not found."
}Too Many Requests. The plan or Agent Actions budget limit has been reached.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Plan or Budget Limit reached.",
"statusCode": 429,
"message": " Please change the plan or Agent Actions budget in sanity.io/manage."
}Internal Server Error. The language model request failed.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "LLM API error",
"statusCode": 500,
"message": "One of our API providers failed to execute a task. Please try again later."
}Transform a document
/transform/{dataset}Transforms a source document. By default, the changes are written to the source document. To write them to a different document, set targetDocument.
Examples and implementation details can be found in the Transform documentation.
Path parameters
Request body application/json
The schema identifier reported by
sanity deployorsanity schema deploy.Example:_.schemas.default- conditionalPathsobject
Allows the instruction to modify conditional
readOnlyorhiddenfields. Does not apply to fields explicitly set as hidden or readOnly in the schema.Show child attributes
When false, forces all conditional readOnly fields to be writable.
- booleandefault:
trueWhen false, forces all conditional hidden fields to be writable.
- pathsarray
Override the default behavior of individual conditional paths.
Set to true to mutate published documents. By default, Agent Actions will never mutate a published document. They will use a draftId if a publishedId is provided. Operations on drafts receive initial state from the published document, if no draft exists. If a draft exists, it is used as the initial state. The returned
_idwill be that of the modified document.Documents set to
liveEdit: truewill be mutated as ifforcePublishedWrite: true.When true, documents aren't created or mutated.
When true, requests occur in the background. True is incompatible with
noWrite: true.- temperaturenumber
Controls the level of variance in the response. A higher value returns more variation in responses, while a lower value returns more predictable responses. Defaults to
0.3for Generate, and0for Transform and Translate.Example:0.7 - localeSettingsobject
When provided with locale settings, Agent Actions write to
dateanddatetimefields. Otherwise, those fields are ignored.Example{"locale":"en-US","timeZone":"America/New_York"}Show child attributes
A valid Unicode BCP 47 locale identifier. This will affect how natural language time and date phrases are parsed and presented.
Example:en-USA valid IANA time zone identifier. This will ensure dates and times are interpreted correctly relative to the user's local time.
Example:America/New_York
The ID of the source document to transform.
Example:123The target document to transform and the operation to perform. If omitted, the source document (
documentId) will be used as the target.Show child attributes
Describes the instruction. Reference
instructionParamsusing the$variablesyntax.Example:Create a new document with a title like $title, that matches the style of $externalTitle, and generate content based on the $backgroundContext.- instructionParamsobject
Parameter values available to reference in the instruction.
There are four types of parameters:
constant: Set a static value. Ex:paramName: { type: 'constant', value: 'New title'}, or the shorthandparamName: 'New title'field: Target a field in the document to set the parameter to its value. Also takes an optionaldocumentIdto target a field in a different document. Ex:paramName: { type: 'field', path: 'poster'}groq: Set the parameter to the result of a GROQ query. Ex:paramName: { type: 'groq', query: '*[_type == $docType]', params: { 'docType': 'article'} }document: Set the parameter to the value of the entire document. If nodocumentIdis provided, the current document is returned. Prompt requests requiredocumentIdforfieldanddocumentparameters. Ex:paramName: { type: 'document', documentId: '123'}
Defines which parts of the document will be affected by the Transform instruction.
Show child attributes
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }] Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- instructionstring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- instructionstring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - operationdefault:
"set"Sets the default operation for all paths in the target.
Operation types:
- 'set': (Default) Overwrites and replaces the full field value.
- 'image-description': Lets the transform action select an image asset, select a field, and describe the image in the field. You can also set an
imageUrlto describe remote images.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
Show child attributes
- stringenum:
"set"
Use to describe an image asset. It will find an adjacent asset if located in the image path. For external paths, use sourcePath. For remote images, use imageUrl.
- imageUrlstring (uri)
The URL of the image to describe. Must use HTTPS. Can't be combined with
sourcePath. - sourcePatharray
A list of path segments, from the document root down.
Example["body",{"_key":"someKey"},"title"]Show child attributes
items
Further fields truncatedFurther fields truncated
- includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
Further fields truncatedFurther fields truncated- instructionstring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - operationdefault:
"set"Sets the default operation for all paths in the target.
Operation types:
- 'set': (Default) Overwrites and replaces the full field value.
- 'image-description': Lets the transform action select an image asset, select a field, and describe the image in the field. You can also set an
imageUrlto describe remote images.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
Show child attributes
Further fields truncatedFurther fields truncated - includearray
Show child attributes
items
Further fields truncatedFurther fields truncated
- operationdefault:
"set"Sets the default operation for all paths in the target.
Operation types:
- 'set': (Default) Overwrites and replaces the full field value.
- 'image-description': Lets the transform action select an image asset, select a field, and describe the image in the field. You can also set an
imageUrlto describe remote images.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
Show child attributes
- stringenum:
"set"
Use to describe an image asset. It will find an adjacent asset if located in the image path. For external paths, use sourcePath. For remote images, use imageUrl.
- imageUrlstring (uri)
The URL of the image to describe. Must use HTTPS. Can't be combined with
sourcePath. - sourcePatharray
A list of path segments, from the document root down.
Example["body",{"_key":"someKey"},"title"]Show child attributes
items
- string
Field name
Example:body
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }] Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- instructionstring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncateditems
Further fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncateditems
Further fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- instructionstring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - operationdefault:
"set"Sets the default operation for all paths in the target.
Operation types:
- 'set': (Default) Overwrites and replaces the full field value.
- 'image-description': Lets the transform action select an image asset, select a field, and describe the image in the field. You can also set an
imageUrlto describe remote images.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
Show child attributes
- stringenum:
"set"
Use to describe an image asset. It will find an adjacent asset if located in the image path. For external paths, use sourcePath. For remote images, use imageUrl.
- imageUrlstring (uri)
The URL of the image to describe. Must use HTTPS. Can't be combined with
sourcePath. - sourcePatharray
A list of path segments, from the document root down.
Example["body",{"_key":"someKey"},"title"]Show child attributes
- includearray
Show child attributes
items
Further fields truncatedFurther fields truncated- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
- instructionstring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - operationdefault:
"set"Sets the default operation for all paths in the target.
Operation types:
- 'set': (Default) Overwrites and replaces the full field value.
- 'image-description': Lets the transform action select an image asset, select a field, and describe the image in the field. You can also set an
imageUrlto describe remote images.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
Show child attributes
- includearray
Show child attributes
- operationdefault:
"set"Sets the default operation for all paths in the target.
Operation types:
- 'set': (Default) Overwrites and replaces the full field value.
- 'image-description': Lets the transform action select an image asset, select a field, and describe the image in the field. You can also set an
imageUrlto describe remote images.
Use
includeto override the defaultoperationfor specific paths.Nested fields inherit the operation of their parent, and fall back to the top level target operation unless otherwise specified.
Show child attributes
- stringenum:
"set"
Use to describe an image asset. It will find an adjacent asset if located in the image path. For external paths, use sourcePath. For remote images, use imageUrl.
- imageUrlstring (uri)
The URL of the image to describe. Must use HTTPS. Can't be combined with
sourcePath. - sourcePatharray
A list of path segments, from the document root down.
Example["body",{"_key":"someKey"},"title"]Show child attributes
items
- string
Field name
Example:body
items
Responses
Request was successful, returning the resulting document.
When some paths failed or were skipped, the response includes the x-transform-* headers.
- object
A Sanity document shape.
Request accepted and processed asynchronously (async: true). Returns the ID of the document that will be modified.
- _idstring
The ID of the document.
application/json{
"_id": "drafts.123"
}Bad request. The request body is invalid, contains incompatible parameters, or uses an API version other than vX.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"statusCode": 400,
"message": "Invalid request body",
"statusMessage": "Bad Request",
"error": "Validation error: Required at \"schemaId\"",
"details": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"schemaId"
],
"message": "Required"
}
]
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Incompatible parameters: async and noWrite cannot both be true"
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Agent Actions are only available on apiVersion vX"
}Unauthorized. The token is missing, invalid, or expired.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Unauthorized",
"statusCode": 401,
"message": "Session expired"
}Forbidden. AI features are disabled for the project's organization.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "AI features have been disabled at this organization's request.",
"statusCode": 403,
"message": "Feature disabled.",
"organization": {
"id": "oABC123",
"name": "Example organization"
}
}Not Found. The document or the schema could not be found.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Not Found",
"statusCode": 404,
"message": "No document exists for id: \"123\""
}{
"error": "Not Found",
"statusCode": 404,
"message": "Schema for schemaId '_.schemas.default' could not be not found."
}Too Many Requests. The plan or Agent Actions budget limit has been reached.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Plan or Budget Limit reached.",
"statusCode": 429,
"message": " Please change the plan or Agent Actions budget in sanity.io/manage."
}Internal Server Error. The language model request failed.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "LLM API error",
"statusCode": 500,
"message": "One of our API providers failed to execute a task. Please try again later."
}Translate a document
/translate/{dataset}Translates a source document. By default, the translation is written to the source document. To write it to a different document, set targetDocument.
Examples and implementation details can be found in the Translate documentation.
Path parameters
Request body application/json
The schema identifier reported by
sanity deployorsanity schema deploy.Example:_.schemas.default- conditionalPathsobject
Allows the instruction to modify conditional
readOnlyorhiddenfields. Does not apply to fields explicitly set as hidden or readOnly in the schema.Show child attributes
When false, forces all conditional readOnly fields to be writable.
- booleandefault:
trueWhen false, forces all conditional hidden fields to be writable.
- pathsarray
Override the default behavior of individual conditional paths.
Set to true to mutate published documents. By default, Agent Actions will never mutate a published document. They will use a draftId if a publishedId is provided. Operations on drafts receive initial state from the published document, if no draft exists. If a draft exists, it is used as the initial state. The returned
_idwill be that of the modified document.Documents set to
liveEdit: truewill be mutated as ifforcePublishedWrite: true.When true, documents aren't created or mutated.
When true, requests occur in the background. True is incompatible with
noWrite: true.- temperaturenumber
Controls the level of variance in the response. A higher value returns more variation in responses, while a lower value returns more predictable responses. Defaults to
0.3for Generate, and0for Transform and Translate.Example:0.7 - localeSettingsobject
When provided with locale settings, Agent Actions write to
dateanddatetimefields. Otherwise, those fields are ignored.Example{"locale":"en-US","timeZone":"America/New_York"}Show child attributes
A valid Unicode BCP 47 locale identifier. This will affect how natural language time and date phrases are parsed and presented.
Example:en-USA valid IANA time zone identifier. This will ensure dates and times are interpreted correctly relative to the user's local time.
Example:America/New_York
The ID of the source document to translate.
Example:123The target document to transform and the operation to perform. If omitted, the source document (
documentId) will be used as the target.Show child attributes
- fromLanguageobject
- styleGuidestring
A style guide for the translation.
Example:Use a formal tone and avoid using contractions. - styleGuideParamsobject
Parameter values available to reference in the instruction.
There are four types of parameters:
constant: Set a static value. Ex:paramName: { type: 'constant', value: 'New title'}, or the shorthandparamName: 'New title'field: Target a field in the document to set the parameter to its value. Also takes an optionaldocumentIdto target a field in a different document. Ex:paramName: { type: 'field', path: 'poster'}groq: Set the parameter to the result of a GROQ query. Ex:paramName: { type: 'groq', query: '*[_type == $docType]', params: { 'docType': 'article'} }document: Set the parameter to the value of the entire document. If nodocumentIdis provided, the current document is returned. Prompt requests requiredocumentIdforfieldanddocumentparameters. Ex:paramName: { type: 'document', documentId: '123'}
- protectedPhrasesarray
A list of phrases that should not be translated. Use this instead of the style guide for phrases or words you want the translation to leave unchanged.
Show child attributes
items
- string
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayTarget defines which parts of the document are affected by the instruction. You can configure multiple parts of the document separately.
Omitting target will set the document as the root. When multiple targets are provided, they will coalesce into a single target sharing a common root.
Example:
{ "path": "body", "operation": "append", "maxPathDepth": 3, "include": [ { "path": "sections", "types": { "include": ["text", "image"] } } ] }Show child attributes
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }] Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- styleGuidestring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
- string
Field name
Example:body
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- styleGuidestring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
Further fields truncatedFurther fields truncated- styleGuidestring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
Further fields truncatedFurther fields truncated
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe maximum depth of the document paths the instruction can write to. When
targetis omitted, Transform and Translate use a depth of 12. Depth is based on field path segments:titlehas a depth of 1author.namehas a depth of 2array[_key="123"].titlehas a depth of 3
Use caution when setting this value too high in studios with recursive document schemas as it may cause performance and response quality issues.
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }] Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- styleGuidestring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
- string
Field name
Example:body
- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
Further fields truncatedFurther fields truncateditems
Further fields truncated - excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
items
Further fields truncatedFurther fields truncateditems
Further fields truncated Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }- styleGuidestring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
Further fields truncatedFurther fields truncated- pathrequired
A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayShow child attributes
- excludearray
Define fields or array items to exclude from the instruction. Any omitted fields or array items are implicitly included. By default, all children up to the maxPathDepth are included.
Example:
["metadata", "draft", { "_key": "tempSection" }]Show child attributes
Configure which schema types to include or exclude from the instruction: array item types, or all fields of a type directly under the target path.
includeandexcludeare mutually exclusive.Example:
{ "include": ["text", "image", "video"] }Show child attributes
- styleGuidestring
Describes the instructions for the included targets. References the top-level
instructionParamsusing the$variablesyntax.Example:Update the $title based on the $backgroundContext. - includearray
Show child attributes
items
Responses
Request was successful, returning the resulting document.
When some paths failed or were skipped, the response includes the x-transform-* headers.
- object
A Sanity document shape.
Request accepted and processed asynchronously (async: true). Returns the ID of the document that will be modified.
- _idstring
The ID of the document.
application/json{
"_id": "drafts.123"
}Bad request. The request body is invalid, contains incompatible parameters, or uses an API version other than vX.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"statusCode": 400,
"message": "Invalid request body",
"statusMessage": "Bad Request",
"error": "Validation error: Required at \"schemaId\"",
"details": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"schemaId"
],
"message": "Required"
}
]
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Incompatible parameters: async and noWrite cannot both be true"
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Agent Actions are only available on apiVersion vX"
}Unauthorized. The token is missing, invalid, or expired.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Unauthorized",
"statusCode": 401,
"message": "Session expired"
}Forbidden. AI features are disabled for the project's organization.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "AI features have been disabled at this organization's request.",
"statusCode": 403,
"message": "Feature disabled.",
"organization": {
"id": "oABC123",
"name": "Example organization"
}
}Not Found. The document or the schema could not be found.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Not Found",
"statusCode": 404,
"message": "No document exists for id: \"123\""
}{
"error": "Not Found",
"statusCode": 404,
"message": "Schema for schemaId '_.schemas.default' could not be not found."
}Too Many Requests. The plan or Agent Actions budget limit has been reached.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Plan or Budget Limit reached.",
"statusCode": 429,
"message": " Please change the plan or Agent Actions budget in sanity.io/manage."
}Internal Server Error. The language model request failed.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "LLM API error",
"statusCode": 500,
"message": "One of our API providers failed to execute a task. Please try again later."
}Prompt the LLM for a response
/prompt/{dataset}Prompt the LLM for a response. Does not interact with documents beyond fetching content as context when requested. Use for tasks that don't require manipulating documents, such as generating details that you may want to use with other Agent Actions.
Examples and implementation details can be found in the Prompt documentation.
Path parameters
Request body application/json
Describes the instruction. Reference
instructionParamsusing the$variablesyntax.Example:Create a new document with a title like $title, that matches the style of $externalTitle, and generate content based on the $backgroundContext.- instructionParamsobject
Parameter values available to reference in the instruction.
There are four types of parameters:
constant: Set a static value. Ex:paramName: { type: 'constant', value: 'New title'}, or the shorthandparamName: 'New title'field: Target a field in the document to set the parameter to its value. Also takes an optionaldocumentIdto target a field in a different document. Ex:paramName: { type: 'field', path: 'poster'}groq: Set the parameter to the result of a GROQ query. Ex:paramName: { type: 'groq', query: '*[_type == $docType]', params: { 'docType': 'article'} }document: Set the parameter to the value of the entire document. If nodocumentIdis provided, the current document is returned. Prompt requests requiredocumentIdforfieldanddocumentparameters. Ex:paramName: { type: 'document', documentId: '123'}
The temperature to use for the prompt. Controls how much variance there will be in responses.
Example:0.5The format of the response. If
json, the instruction must include the word "json", in any letter case.
Responses
Request was successful. Returns text/plain when format is string, and the JSON the instruction asks for when format is json.
- objectExample
{"text":"Hello, world!"}
text/plainBad request. The request body is invalid, contains incompatible parameters, or uses an API version other than vX.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"statusCode": 400,
"message": "Invalid request body",
"statusMessage": "Bad Request",
"error": "Validation error: Required at \"schemaId\"",
"details": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"schemaId"
],
"message": "Required"
}
]
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Incompatible parameters: async and noWrite cannot both be true"
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Agent Actions are only available on apiVersion vX"
}Unauthorized. The token is missing, invalid, or expired.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Unauthorized",
"statusCode": 401,
"message": "Session expired"
}Forbidden. AI features are disabled for the project's organization.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "AI features have been disabled at this organization's request.",
"statusCode": 403,
"message": "Feature disabled.",
"organization": {
"id": "oABC123",
"name": "Example organization"
}
}Not Found. The document or the schema could not be found.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Not Found",
"statusCode": 404,
"message": "No document exists for id: \"123\""
}{
"error": "Not Found",
"statusCode": 404,
"message": "Schema for schemaId '_.schemas.default' could not be not found."
}Too Many Requests. The plan or Agent Actions budget limit has been reached.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Plan or Budget Limit reached.",
"statusCode": 429,
"message": " Please change the plan or Agent Actions budget in sanity.io/manage."
}Internal Server Error. The language model request failed.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "LLM API error",
"statusCode": 500,
"message": "One of our API providers failed to execute a task. Please try again later."
}Make a schema-aware patch to a document
/patch/{dataset}A schema-aware patch API that validates the provided paths and values against the target schema.
This operation doesn't use an LLM and only uses regular Sanity billing for API requests.
Unknown properties in the request body are rejected with a 400.
Examples and implementation details can be found in the Patch documentation.
Path parameters
Request body application/json
The schema identifier reported by
sanity deployorsanity schema deploy.Example:_.schemas.default- conditionalPathsobject
Allows the instruction to modify conditional
readOnlyorhiddenfields. Does not apply to fields explicitly set as hidden or readOnly in the schema.Show child attributes
When false, forces all conditional readOnly fields to be writable.
- booleandefault:
trueWhen false, forces all conditional hidden fields to be writable.
- pathsarray
Override the default behavior of individual conditional paths.
Set to true to mutate published documents. By default, Agent Actions will never mutate a published document. They will use a draftId if a publishedId is provided. Operations on drafts receive initial state from the published document, if no draft exists. If a draft exists, it is used as the initial state. The returned
_idwill be that of the modified document.Documents set to
liveEdit: truewill be mutated as ifforcePublishedWrite: true.When true, documents aren't created or mutated.
When true, requests occur in the background. True is incompatible with
noWrite: true.- documentIdstring
The ID of the document to patch. Either
documentIdortargetDocumentis required. They're mutually exclusive. The operation to perform and the target document to transform.
Show child attributes
- _idstring
The document type to create.
- initialValuesobject
Define any initial values for the document. Similar to initial value templates in Studio, this is useful for setting fields to pre-determined values directly without going through the LLM.
Example{"author":{"_ref":"abc123456","_type":"reference"}}
The document type to create.
- initialValuesobject
Define any initial values for the document. Similar to initial value templates in Studio, this is useful for setting fields to pre-determined values directly without going through the LLM.
Example{"author":{"_ref":"abc123456","_type":"reference"}}
The document type to create.
- initialValuesobject
Define any initial values for the document. Similar to initial value templates in Studio, this is useful for setting fields to pre-determined values directly without going through the LLM.
Example{"author":{"_ref":"abc123456","_type":"reference"}}
- targetrequired
Show child attributes
Determines how the target path will be patched.
'set': an overwriting operation: sets the full field value for primitive targets, and merges the provided value with existing values for objects'append':- array fields: appends new items to the end of the array,
- string fields: '"existing content" "new content"'
- text fields: '"existing content"\n"new content"'
- number fields: existing + new
- other field types not mentioned will set instead (dates, url)
'mixed': sets non-array fields, and appends to array fields'unset': removes whatever value is on the target path
All operations except unset require a
value.Appending in the middle of arrays
To append to an array, use the 'append' operation and provide an array value with one or more array items.
target: {path: ['array'], operation: 'append', value: [{_type: 'item', _key: 'a'}]}will append the items in the value to the existing array. To insert in the middle of the array, usetarget: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append', value: [{_type: 'item', _key: 'a'}]}. Here,{_type: 'item', _key: 'a'}will be appended after the array item with key'appendAfterKey'It is optional to provide a _key for inserted array items; if one isn't provided, it will be generated.A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe value to write at
path. Required for every operation exceptunset. Can't benull.
Determines how the target path will be patched.
'set': an overwriting operation: sets the full field value for primitive targets, and merges the provided value with existing values for objects'append':- array fields: appends new items to the end of the array,
- string fields: '"existing content" "new content"'
- text fields: '"existing content"\n"new content"'
- number fields: existing + new
- other field types not mentioned will set instead (dates, url)
'mixed': sets non-array fields, and appends to array fields'unset': removes whatever value is on the target path
All operations except unset require a
value.Appending in the middle of arrays
To append to an array, use the 'append' operation and provide an array value with one or more array items.
target: {path: ['array'], operation: 'append', value: [{_type: 'item', _key: 'a'}]}will append the items in the value to the existing array. To insert in the middle of the array, usetarget: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append', value: [{_type: 'item', _key: 'a'}]}. Here,{_type: 'item', _key: 'a'}will be appended after the array item with key'appendAfterKey'It is optional to provide a _key for inserted array items; if one isn't provided, it will be generated.A document path: either a single path segment, or an array of segments.
Examples:
"body" // Field name { "_key": "section1" } // Array item by key ["body", { "_key": "section1" }, "title"] // Path arrayThe value to write at
path. Required for every operation exceptunset. Can't benull.
items
Responses
Request was successful, returning the resulting document.
The ID of the document.
Example:123The type of the document.
Example:articleThe creation date of the document.
Example:2025-03-12T19:28:18ZThe last update date of the document.
Example:2025-03-12T19:28:18Z- _revstring
The revision number of the document.
Example:rev123
Request accepted and processed asynchronously (async: true). Returns the ID of the document that will be modified.
- _idstring
The ID of the document.
application/json{
"_id": "drafts.123"
}Bad request. The request body is invalid, contains incompatible parameters, or uses an API version other than vX.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"statusCode": 400,
"message": "Invalid request body",
"statusMessage": "Bad Request",
"error": "Validation error: Required at \"schemaId\"",
"details": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"schemaId"
],
"message": "Required"
}
]
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Incompatible parameters: async and noWrite cannot both be true"
}{
"error": "Bad Request",
"statusCode": 400,
"message": "Agent Actions are only available on apiVersion vX"
}Unauthorized. The token is missing, invalid, or expired.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Unauthorized",
"statusCode": 401,
"message": "Session expired"
}Forbidden. AI features are disabled for the project's organization.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "AI features have been disabled at this organization's request.",
"statusCode": 403,
"message": "Feature disabled.",
"organization": {
"id": "oABC123",
"name": "Example organization"
}
}Not Found. The document or the schema could not be found.
Error name. For validation errors, a summary of the failed validations.
Example:Bad RequestHTTP status code
Example:400Error message describing the issue
Example:Incompatible parameters: async and noWrite cannot both be true- statusMessagestring
HTTP status text. Only present on request validation errors.
Example:Bad Request - detailsarray
The individual validation issues. Only present on request validation errors.
- organizationobject
The organization that disabled AI features. Only present on that
403error.
application/json{
"error": "Not Found",
"statusCode": 404,
"message": "No document exists for id: \"123\""
}{
"error": "Not Found",
"statusCode": 404,
"message": "Schema for schemaId '_.schemas.default' could not be not found."
}