APIs and SDKs

Schema deployment

Deploy your schema into your dataset to enable deep integration between your content model and Sanity apps.

Since version 3.88.0, Sanity Studio has supported deploying a representation of your content model, in the form of a schema, to your dataset. The schema commands became generally available in that release. It enables integration between your studios and apps like Dashboard and Canvas.

What the schema commands do

The schema commands belong to the sanity schemas group. They let you deploy your schemas at the workspace level to the matching combination of dataset and project ID, which makes them available to Sanity apps and APIs. Requires sanity 3.88.0 or later.

If you aren't logged in with sufficient privileges, provide a deploy token. A deploy token is enough; these commands don't need a write token:

Available commands

sanity schemas deploy

Deploys schema documents to workspace datasets. If you've already run sanity login, you typically have deploy permission by default. In CI environments where sanity login hasn't been executed, you'll need to provide a deploy token.

Options:

  • --workspace <workspace_name>: Deploy for a specific workspace. Essential for studios with multiple project IDs.
  • --tag <tag>: Add a tag suffix to the schema ID, so you can test without overwriting an existing schema.
  • --verbose: Show detailed deployment information, including the schemaId.

Examples:

Deploying a schema is not registering a studio

sanity schemas list

Lists all schemas in the current dataset. Use it to find the schemaId that Agent Actions needs.

Options:

  • --json: Get the schema as JSON.
  • --id <schema_id>: Fetch a single schema by ID.

Examples:

sanity schemas delete

Removes schema documents by id. Useful when you need to remove schemas from Canvas or Agent Actions.

Options:

  • --ids <schema_id_1,schema_id_2,...>: Comma-separated list of schema IDs to delete.
  • --dataset <dataset_name>: Delete schemas from a specific dataset.

Examples:

The --help output for this command still shows IDs in the form sanity.workspace.schema.workspaceName. That form is rejected. Use _.schemas.<workspaceName> or _.schemas.<workspaceName>.tag.<tag> instead.

sanity schemas extract

Extracts the studio schema as a single JSON file, schema.json in the project root by default. It is the prerequisite for sanity typegen generate, which reads that file. See TypeGen. It does not write manifest files.

Options:

  • --path <path>: Destination for the extracted schema file. Defaults to schema.json in the project root, or to schemaExtraction.path from sanity.cli.ts when that is set.
  • --watch: Re-run the extraction as the schema changes.
  • --workspace <name>: The workspace to generate a schema for.
  • --enforce-required-fields: Treat fields marked as required as non-optional. Defaults to false.
  • --force: Overwrite an existing schema file without prompting. Without it, an existing file prompts for confirmation, and fails outright under --unattended.
  • --format <groq-type-nodes>: Output format. groq-type-nodes is both the default and the only available format.
  • --watch-patterns <glob>: Additional glob patterns to watch. Can be specified multiple times.

Examples:

Manifest file structure

The extracted manifest follows this structure:

interface CreateManifest {
  version: number        // Current version: 2
  createdAt: string      // ISO timestamp
  workspaces: ManifestWorkspaceFile[]
}

interface ManifestWorkspaceFile {
  name: string
  title?: string
  subtitle?: string
  basePath: string
  dataset: string
  projectId: string
  schema: string        // filename with serialized schema
  tools: string         // filename
  icon: string | null
}

How manifest files are produced

Two commands write manifest files:

  • sanity deploy: writes manifest files into your build output when deploying to Sanity hosting. It skips that step for --external deployments.
  • sanity manifest extract: writes manifest files to a directory you choose with --path. This is the only way to produce them without deploying to Sanity hosting.

More schema commands

Two more commands belong to this group:

sanity schemas validate

Validates schema types in a workspace. sanity schemas deploy runs the same validation before deploying and reports the same output, so a schema error here also blocks a deployment.

Options:

  • --workspace <name>: The workspace to validate.
  • --format <pretty|ndjson|json>: Output format. Default: pretty.
  • --level <error|warning>: Minimum reporting level. Default: warning.

sanity manifest extract

Extracts the studio configuration as one or more JSON manifest files. This is the only command that writes manifest files without deploying to Sanity hosting, and it is intended for use with Create.

Options:

  • --path: destination directory for the manifest files. Default: dist/static.

Related commands

  • sanity deploy - Deploys a studio to Sanity hosting and includes schema deployment in the process. Use sanity deploy --external to register a studio you host yourself.
  • sanity typegen generate - Creates TypeScript types from schema types and GROQ queries

Manifests, permissions, and registration

  • You don't need to keep your manifest in version control since it's derived from your codebase.
  • For embedded studios, the manifest has to be served at <studio-url>/static/create-manifest.json. Write it there with npx sanity@latest manifest extract --path. No other command writes those files.
  • Serving the manifest at your own domain does not register the studio. An externally hosted studio has to be registered with npx sanity deploy --external before Dashboard and Media Library can resolve its workspaces.
  • All schema commands need the deployStudio grant on sanity.project. A deploy token carries it; a write token isn't required.

Errors you might see

  • Failed to deploy schemas: The deployment failed. The underlying reason follows on the next line of output.
  • Failed to deploy 1/3 schemas. Successfully deployed 2/3 schemas. Some workspaces deployed and others didn't. The output names which ones failed.
  • No permissions to write schema for workspace "..." in dataset "...". For multi-project workspaces, set SANITY_AUTH_TOKEN environment variable to a token with access to the workspace projects. The token lacks the deployStudio grant, or it doesn't cover every project a multi-project workspace spans.

Was this page helpful?