Install and configure Sanity AI Assist

Sanity AI Assist is a content-aware Large Language Model-type assistant that can help you automate repetitive tasks and chores when working in Sanity Studio.

Enterprise Feature

This article is about a feature that is currently available to enterprise customers in a closed beta. To enable the feature for your project, get in touch!

This article deals with the practicalities of installing and configuring the Sanity AI Assist plugin. You can learn more about how to enable the feature for your project and how to use it once you have access by visiting the following links:

Installation

Using npm, or your preferred package manager, update your studio to the latest version, and install the AI Assist plugin.

npm install sanity@latest @sanity/assist

Add the plugin to your studio configuration

In sanity.config.ts, add assist to the plugins array:

import { assist } from '@sanity/assist'

export default defineConfig({
  /* other config */
  plugins: [
    /* other plugins */
    assist()
  ]
})

Enabling the AI Assist API

After installing and adding the plugin and having the AI Assist feature enabled for your project and its datasets, you need to create a token for the plugin to access the AI Assist API. This needs to be done by a member on the project with token creation permissions (typically someone with an admin or developer role).

  • Start the studio and open any document
  • Click the sparkle icon(✨) in the document header near the close document X-button
  • Then select Manage instructions
  • Selecting Manage instructions will open an inspector panel
  • Click the Enable AI assistance button to create a token and enable AI Assist for everyone with access to the project

You will find a new API token entry for your project named “Sanity AI” in your project's API settings on sanity.io/manage.

The plugin will now work for any dataset in your project.

Gotcha

Note: You can revoke this token at any time to disable Sanity AI Assist service. A new token has to be generated via the plugin UI for it to work again.

Schema configuration

By default, most object, array, and string field types have AI writing assistance enabled. Your assistant can write to all compatible fields that it detects.

The assistant can also create array items, including Portable Text blocks, when the type has been imported to the Studio's schema as a custom type (learn more about strict schemas).

Disable AI Assist for a schema type

// this will disable AI assistance wherever it is used,
// ie: as field, document, array types
defineType({
 name: 'policy',
  type: 'document',
  options: {
    aiWritingAssistance: {exclude: true}
 },
  fields: [
    // ...
  ]
})

Disable for a nested field type

// this disables AI assistance only for the specific field
defineType({
 name: 'product',
  type: 'object',
  fields: [
    defineField({
      name: 'sku',
      type: 'string',
      options: {
        aiWritingAssistance: {exclude: true}
     }
  })
  ]
})

Disable for an array type

// this disables s AI assistance for the specific array member
// if all types in the `of` array are excluded, the array type is also considered excluded
defineType({
 name: 'myArray',
  type: 'array',
  of: [
    defineArrayMember({
      type: 'someType',
      options: {
        aiWritingAssistance: {exclude: true}
     }
  })
  ]
})

Unsupported types

The following types are not supported, and behave as excluded types:

Fields with these types will not be changed by the assistant, do not have AI Assist actions, and cannot be referenced in instructions.

Objects where all fields are excluded or unsupported and arrays where all member types are excluded or unsupported will also be excluded.

Included document types

This plugin adds an AI Context document type.

If your Studio uses Structure Builder to configure the studio structure, you might have to add this document type to your structure.

The document type name can be imported from the plugin:

import {contextDocumentTypeName} from '@sanity/assist'

// put into structure in structure  
S.documentTypeListItem(contextDocumentTypeName)

Troubleshooting

Caveats

Large Language Models (LLMs) are a new technology. Constraints and limitations are still being explored, but some common caveats to the field that you may run into using AI Assist are:

  • Limits to instruction length: Long instructions on deep content structures may exhaust model context
  • Timeouts: To be able to write structured content, we're using the largest language models - long-running results may time out or intermittently fail
  • Limited capacity: The underlying LLM APIs used by AI Assist are resource constrained

There are limits to how much text the AI can process when processing an instruction. Under the hood, the AI Assist will add information about your schema, which adds to what's commonly referred to as “the context window.”

If you have a very large schema (that is, many document and field types), it can be necessary to exclude types to limit how much of the context window is used for the schema itself.

We recommend excluding any and all types which rarely would benefit from automated workflows. A quick win is typically to exclude array types. It can be a good idea to exclude most non-block types from Portable Text arrays. This will ensure that the Sanity Assist outputs mostly formatted text.

Third party sub-processors

This version of the feature uses OpenAI.com as a third-party sub-processor. Their security posture has been vetted by Sanity's security team, and approved for use.

Was this article helpful?