### Development Server Confirmation Source: https://www.sanity.io/docs/app-sdk/sdk-configuration Example output confirming the development server has started and providing a link to view your app. ```bash Dev server started on port 3333 View your app in the Sanity dashboard here: https://www.sanity.io/@[ORGANIZATION-ID]?dev=http%3A%2F%2Flocalhost%3A3333 ``` -------------------------------- ### Sanity Client Setup with Project ID Source: https://www.sanity.io/docs/changelog/feed/rss?full=true Example of how to set up the Sanity client, showing a placeholder for projectId that can be dynamically populated. ```javascript const client = createClient({ projectId: "PROJECT_ID", dataset: "DATASET_NAME", useCdn: true, apiVersion: "2021-03-25", // Add other configuration options here }); ``` -------------------------------- ### Welcome Event Example Source: https://www.sanity.io/docs/http-reference/listen An example of a 'welcome' SSE message. ```APIDOC ## Welcome Event ### Description Sent when a new SSE connection is established. ### Event Type `welcome` ### Data Example ```json { "listenerName": "Ua6BR3GwQ14cnZXrgwCdsF" } ``` ``` -------------------------------- ### Prompt Coding Agent for Setup Source: https://www.sanity.io/docs/ai/sanity-context This is an example prompt to instruct a coding agent to use the 'create-agent-with-sanity-context' skill. The skill assists in setting up Sanity Context within your project. ```text Use the create-agent-with-sanity-context skill to help me build an agent in this project. ``` -------------------------------- ### Initialize New App with App SDK Quickstart Template Source: https://www.sanity.io/docs/app-sdk/installation-and-development Use this command to bootstrap a new React application with the necessary dependencies and boilerplate preconfigured for the App SDK. ```sh npx sanity@latest init --template app-quickstart ``` -------------------------------- ### Install a Language Plugin for Sanity Studio Source: https://www.sanity.io/docs/changelog/607ed949-92b7-4bdd-a276-ee0ba04f50ea?from=%2Fdocs%2Fcli-reference%2Fcli-config%2Fchangelog&fromId=0fffed3b-2e7c-4fdb-a97b-1a82e67e9f0e&fromTitle=CLI+Configuration Install the specific language plugin for your desired locale, for example, Norwegian Bokmål. ```bash npm install @sanity/locale-nb-no ``` -------------------------------- ### Initialize Shopify Reference Studio Source: https://www.sanity.io/docs/apis-and-sdks/sanity-connect-for-shopify Run this command to install a production-ready reference studio pre-configured for Shopify. Replace placeholders with your actual Project ID and Dataset Name. ```sh npx @sanity/cli init --template shopify --project PROJECT_ID --dataset DATASET_NAME ``` -------------------------------- ### Start Dev Server on Different Port Source: https://www.sanity.io/docs/app-sdk/sdk-quickstart If port 3333 is in use, you can start the development server on an alternative port by passing the --port flag. This example starts the server on port 3334. ```sh npm run dev -- --port 3334 ``` -------------------------------- ### Get Dataset Grants Example Source: https://www.sanity.io/docs/http-reference/roles Example JSON response for retrieving dataset grants. It details filter modes, grants with parameters, and configuration filters. ```json { "sanity.document.filter.mode": [ { "grants": [ { "name": "mode", "params": { "mode": "publish", "history": true, "datasetPolicyName": "default" } } ], "config": { "filter": "_id in path(\"**\")" } } ] } ``` -------------------------------- ### Start Server with Custom Host Source: https://www.sanity.io/docs/cli-reference/start Use this command to start the preview server and listen on all network interfaces. This is useful for accessing the preview from other devices on the same network. ```sh sanity start --host=0.0.0.0 ``` -------------------------------- ### Translate with Target-Level Style Guide Source: https://www.sanity.io/docs/agent-actions/targets-paths Use the `translate` action to translate content, allowing per-path style guides. This example translates 'title' using a default style guide and 'description' with a specific lowercase instruction. ```javascript await client.agent.action.translate({ schemaId: 'default-schema', documentId: 'drafts.id', fromLanguage: { id: 'en-GB',title: 'English' }, toLanguage: { id: 'no-NB', title: 'Norwegian Bokmål' }, languageFieldPath: ['language'], styleGuide: 'Follow the vibe when translating: $vibe', styleGuideParams: { vibe: { type: 'field', path: ['vibe']} }, target: [ {path: 'title'}, // Uses the default style guide {path: 'description', styleGuide: 'Only lowercase.' }, // Uses its own style guide ] }) ``` -------------------------------- ### Start CLI Command Source: https://www.sanity.io/docs/cli-reference/start Starts a server to preview a production build. You can specify an output directory, host, and port. ```APIDOC ## sanity start ### Description Starts a server to preview a production build. ### Usage ```sh sanit start [OUTPUTDIR] ``` ### Arguments #### [OUTPUTDIR] - **OUTPUTDIR** (string) - Optional - Output directory for the build. ### Flags #### --host= - **--host** (string) - The local network interface at which to listen. #### --port= - **--port** (number) - TCP port to start server on. ### Examples #### Basic Usage ```sh sanit start --host=0.0.0.0 sanit start --port=1942 sanit start some/build-output-dir ``` ``` -------------------------------- ### Standalone Functions Project Structure Source: https://www.sanity.io/docs/blueprints/project-layout-and-monorepos Example directory structure for a standalone Sanity Functions project. Dependencies are managed at the root `package.json` and installed via `pnpm install`. ```text my-project/ ├─ functions/ │ └─ log-event/ │ └─ index.ts ├─ package.json ├─ pnpm-lock.yaml └─ sanity.blueprint.ts ``` -------------------------------- ### Get Dataset ACL Example Source: https://www.sanity.io/docs/http-reference/roles Example JSON response for retrieving a dataset's access control list (ACL). It shows filter rules and associated grants. ```json [ { "filter": "_id in path(\"**\")", "grants": [ "read", "update", "create", "history" ] } ] ``` -------------------------------- ### Navigate to Project Directory Source: https://www.sanity.io/docs/app-sdk/sdk-quickstart Change into the newly created project directory to begin development. ```sh cd my-cool-project ``` -------------------------------- ### Start Server on a Specific Port Source: https://www.sanity.io/docs/cli-reference/start This command starts the preview server on a custom TCP port. Use this if the default port is already in use or if you need to specify a particular port for your setup. ```sh sanity start --port=1942 ``` -------------------------------- ### Start Local Preview Server with Custom Host Source: https://www.sanity.io/docs/cli-reference/preview Use this command to start a local preview server listening on all network interfaces. This is useful for accessing the preview from other devices on the same network. ```sh sanity preview --host=0.0.0.0 ``` -------------------------------- ### Install Prettier Code Formatting Function Blueprint Source: https://www.sanity.io/docs/changelog/0c948fdd-2d78-4b7c-a3fe-44e664e75671 Install a function blueprint for formatting code blocks using Prettier. This command-line instruction adds the necessary setup for code formatting. ```bash npx sanity blueprints add function --example prettier-format-code ``` -------------------------------- ### Example Welcome Event from Listen API Source: https://www.sanity.io/docs/listening This example demonstrates the structure of a 'welcome' event received when establishing a connection to the Listen API. It includes a unique listener name. ```json { "event": "welcome", "data": { "listenerName": "Ua6BR3GwQ14cnZXrgwCdsF" } } ``` -------------------------------- ### Welcome SSE Message Source: https://www.sanity.io/docs/http-reference/live Example of a welcome Server-Sent Events message received when starting a stream. ```json { "id": "MXxhYVlRejdGZUpPMA", "event": "welcome" } ``` -------------------------------- ### Start Server with Output Directory Source: https://www.sanity.io/docs/cli-reference/start Specify a custom directory for the production build output when starting the preview server. This allows you to preview builds located in non-default paths. ```sh sanity start some/build-output-dir ``` -------------------------------- ### Install or Upgrade Sanity Studio Source: https://www.sanity.io/docs/changelog/05bddfa9-2297-4dbb-8cf2-e242ff368e49?from=%2Fdocs%2Fcli-reference%2Fcli-schemas%2Fchangelog&fromId=a8f5e7dc-50f5-4756-afa9-338b047e22ad&fromTitle=Schemas+CLI+command+reference Refer to the official guide for instructions on installing new Sanity Studio projects or upgrading existing ones. Special attention is needed for versions earlier than 3.37.0. ```bash sanity install ``` -------------------------------- ### Initialize Bare Sanity Studio Project Source: https://www.sanity.io/docs/changelog/d443f915-7c84-4070-8d9a-7ee0c187e740 Use the `--bare` flag to skip Studio installation and only go through project and dataset creation. Project ID and dataset names are printed to the console. ```bash npm create sanity -- --bare ``` -------------------------------- ### Install Agent Context Skills Source: https://www.sanity.io/docs/ai/skills Installs agent skills specifically for Agent Context, covering setup of the Agent Context Studio plugin, building AI agents, writing system prompts, and tuning agent instructions. ```sh npx skills add sanity-io/agent-context ``` -------------------------------- ### Install Dependencies Source: https://www.sanity.io/docs/functions/sync-tag-function-quickstart After initializing the blueprint, run your package manager's install command to add the required dependencies. ```sh npm install ``` -------------------------------- ### GROQ Comments Example Source: https://www.sanity.io/docs/groq-reference Comments in GROQ start with // and extend to the end of the line. They can be on their own line or at the end of a code line. ```groq { // Comments can be on a separate line "key": "value" // Or at the end of a line } ``` -------------------------------- ### Sanity Client Setup with Project ID Source: https://www.sanity.io/docs/changelog/0f93c4e7-bf5b-488d-9726-915bffefc5a8 Demonstrates how to set up the Sanity client. Replace PROJECT_ID and DATASET_NAME with your actual project details. ```javascript import { createClient } from 'next-sanity' export const client = createClient({ projectId: 'PROJECT_ID', dataset: 'DATASET_NAME', apiVersion: '2026-05-29', useCdn: true, }) ``` -------------------------------- ### Create a Sanity Dataset Interactively Source: https://www.sanity.io/docs/dataset Starts an interactive process to create a new dataset. The CLI will guide you through the necessary steps. ```bash $ sanity datasets create ``` -------------------------------- ### Start Local Preview Server with Output Directory Source: https://www.sanity.io/docs/cli-reference/preview Use this command to specify a custom output directory for the production build that the preview server will serve. If not specified, it defaults to the current directory. ```sh sanity preview some/build-output-dir ``` -------------------------------- ### Start Local Development Server with npm Source: https://www.sanity.io/docs/development Use these commands to start the local development server for Sanity.io Studios initiated with npm. The alternative method uses `npx` for direct execution. ```bash # For Studios initated with the CLI npm run dev # Alternative method npx sanity dev ``` -------------------------------- ### Initialize New Astro Project Source: https://www.sanity.io/docs/developer-guides/sanity-astro-blog Use this command to create a new Astro project. Select 'A basic, minimal starter' when prompted. ```sh npm create astro@latest ``` -------------------------------- ### Get Role Example Source: https://www.sanity.io/docs/http-reference/roles This JSON object shows the structure of a role retrieved from the Sanity API, including its name, title, description, and grants. ```json { "name": "administrator", "title": "Administrator", "description": "Administrate projects", "isCustom": false, "projectId": "3do82whm", "grants": { "sanity.document.filter.mode": [ { "grants": [ { "name": "mode", "params": { "mode": "publish", "history": true, "datasetPolicyName": "default" } } ], "config": { "filter": "_id in path(\"**\")" } } ] } } ``` -------------------------------- ### Basic Client Setup Source: https://www.sanity.io/docs/apis-and-sdks/js-client-getting-started Create a Sanity client instance with your project ID and dataset. Ensure you replace 'YOUR_PROJECT_ID' and 'YOUR_DATASET' with your actual project details. ```typescript import {createClient} from '@sanity/client' export const client = createClient({ projectId: 'YOUR_PROJECT_ID', dataset: 'YOUR_DATASET', useCdn: true, apiVersion: '2026-03-01', }) ``` -------------------------------- ### Create New Sanity Studio Project Source: https://www.sanity.io/docs/changelog/07656110-93a2-4831-bd04-6616f12bbf1a Use this command to start a new Sanity Studio project without a global CLI installation. ```bash npm create sanity@latest ``` -------------------------------- ### Define a Document Type Source: https://www.sanity.io/docs/sanity-typegen Example of defining a basic 'event' document type with 'name' and 'description' fields. This is a common starting point for Sanity schemas. ```typescript export const event = defineType({ name: 'event', type: 'document', title: 'Event', fields: [ defineField({ name: 'name', type: 'string', title: 'Event name', validation: rule => rule.required() }), defineField({ name: 'description', type: 'text', title: 'Event description' }) ] }) ``` -------------------------------- ### Create a New Sanity Studio Project with npm Source: https://www.sanity.io/docs/changelog/ebf1a25d-b4a3-416b-897b-8242104d4e0a Use this command to start a new Sanity Studio project without a global CLI installation. ```bash npm create sanity@latest ``` -------------------------------- ### Configure Input Component Plugin (Configuration Files) Source: https://www.sanity.io/docs/help/migration-cheat-sheet This example shows how to use a configuration file (`config.dist.json`) to set plugin options, which are then imported and used in your schema and input components. ```json // config.dist.json { "unit": "celsius" } ``` ```javascript // src/config.js import config from 'config:plugin-name' export default { unit: config?.unit || 'celsius' } ``` ```javascript // src/schema.js export default { name: 'plugin-name.schema-type', inputComponent: Input, } ``` ```javascript // src/Input.js import config from './config' export default function Input(props) { return config.unit === 'celsius' ? : } ``` -------------------------------- ### Create New Project with Name, Dataset, Visibility, Template, and Path Source: https://www.sanity.io/docs/cli-reference/init Creates a brand new project with a specified name, dataset, visibility, template, and output path. This command is ideal for setting up a completely new project from scratch with custom configurations. The `-y` flag enables unattended mode. ```sh sanity init -y --project-name "Movies Unlimited" --dataset moviedb --visibility private --template moviedb --output-path /Users/espenh/movies-unlimited ``` -------------------------------- ### Create Dataset Alias Interactively Source: https://www.sanity.io/docs/cli-reference/cli-datasets Initiates the dataset alias creation process with interactive prompts for user input. This is useful when you prefer guided setup. ```sh sanity datasets alias create ``` -------------------------------- ### Start Local Development Server with bun Source: https://www.sanity.io/docs/development Use these commands to start the local development server for Sanity.io Studios initiated with bun. The alternative method uses `bunx` for direct execution. ```bash # For Studios initated with the CLI bun run dev # Alternative method bunx sanity dev ``` -------------------------------- ### Get Utility Type Example Source: https://www.sanity.io/docs/sanity-typegen Extracts deeply nested properties from types, useful for complex page builder schemas. Supports up to 20 levels of nesting. ```typescript import type { Get } from '@sanity/codegen' import type { Page } from './sanity.types' // Extract a deeply nested type type HeroSection = Get ``` -------------------------------- ### Install React Compiler Beta with npm Source: https://www.sanity.io/docs/changelog/839f4b18-788b-4e83-b5d9-8cb838a5be9e Install the React Compiler runtime, Babel plugin, and ESLint plugin using npm. Ensure exact versions are used for the runtime and dev dependencies. ```bash # install using npm npm install --save-exact react-compiler-runtime@beta && npm install --save-exact --save-dev babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta ``` -------------------------------- ### Asynchronous Initial Value with Axios Source: https://www.sanity.io/docs/initial-value-templates Specify an asynchronous function for initial values to fetch data from an API. This example uses axios to get pet data. ```javascript import axios from 'axios' export default { // ... initialValue: async () => { const response = await axios.get('https://api.sanity.io/pets') return {favoritePetName: response.data[0].name} } } ``` -------------------------------- ### Welcome SSEMessage Example Source: https://www.sanity.io/docs/http-reference/listen Represents a welcome message from the server, often containing listener information. ```json { "name": "welcome", "value": { "event": "welcome", "data": { "listenerName": "Ua6BR3GwQ14cnZXrgwCdsF" } } } ``` -------------------------------- ### Sanity Client Configuration Source: https://www.sanity.io/docs/agent-actions/agent-actions-image-generation Configure your Sanity client with project ID, dataset, API version, and editor token. This setup is required for all Agent Actions examples. ```javascript import { createClient } from "@sanity/client"; export const client = createClient({ projectId: '', dataset: '', apiVersion: 'vX', token: '' }) ``` -------------------------------- ### Initialize Project with Specific Project ID and Dataset to a Path Source: https://www.sanity.io/docs/init Initializes a project using unattended mode, specifying the project ID, dataset name, and output path. ```bash $ sanity init -y --project abc123 --dataset production --output-path ~/myproj ``` -------------------------------- ### Retrieve all versions of a document via Doc API Source: https://www.sanity.io/docs/apis-and-sdks/content-releases-cheat-sheet This example shows how to use the Sanity.io Doc API endpoint to get all versions of a document by specifying the `includeAllVersions=true` query parameter. ```sh GET /vX/data/doc/production/movie_70981?includeAllVersions=true ``` -------------------------------- ### Initialize project with authentication token Source: https://www.sanity.io/docs/cli-reference/login This example demonstrates initializing a Sanity project using an authentication token provided via the `SANITY_AUTH_TOKEN` environment variable. This is suitable for server environments or CI/CD pipelines where interactive login is not possible. ```bash SANITY_AUTH_TOKEN=ab97ae7...0f9ff sanity init -y \ --create-project "Movies Unlimited" \ --dataset moviedb \ --visibility private \ --template moviedb \ --output-path /path/to/folder ``` -------------------------------- ### Initialize with Specific Project, Dataset, Template, and Path Source: https://www.sanity.io/docs/cli-reference/init Initializes a project using a specific template, project ID, dataset, and output path. This is useful for starting with a pre-defined project structure, such as the 'moviedb' template. The `-y` flag enables unattended mode. ```sh sanity init -y --project abc123 --dataset staging --template moviedb --output-path . ``` -------------------------------- ### Format Initial Value for Date Field Source: https://www.sanity.io/docs/initial-value-templates When using a 'date' field type, format the initial value to exclude time. This example shows how to get the current date string in 'YYYY-MM-DD' format. ```javascript initialValue: new Date().toISOString().slice(0, 10) ``` -------------------------------- ### Get Schedule by ID Example Source: https://www.sanity.io/docs/scheduling-api This JSON object represents a successful response when retrieving a schedule by its ID. It includes details like schedule ID, name, project, dataset, author, state, and associated documents. ```json { "id": "sch-28MRSuc1Ij4xtNa1rNbhTlMAszj", "name": "March update", "description": "", "projectId": "hb6nr9ev", "dataset": "production", "author": "poLhU1V3X", "state": "succeeded", "stateReason": "execution completed", "documents": [ { "documentId": "f28fe6ce-0454-42c2-8a9a-c469fbf79281", "documentType": "article" } ], "createdAt": "2022-04-27T01:54:31.536236Z", "executeAt": "2022-04-27T01:55:00Z" } ``` -------------------------------- ### Install Sanity Studio using bun Source: https://www.sanity.io/docs/changelog/0868647c-dc51-4f14-9c88-d79e588b9a86?from=%2Fdocs%2Fstudio%2Fstudio-search-config%2Fchangelog&fromId=e89f199b-bc18-4f1f-9b16-b5899cea3514&fromTitle=Studio+search+configuration Initiates a new Studio project without globally installing the Sanity CLI. ```bash bun create sanity@latest ``` -------------------------------- ### Install Beta Sanity UI with bun Source: https://www.sanity.io/docs/changelog/f75445eb-3c3e-4d1e-986d-71a61223aa83?from=%2Fdocs%2Fstudio%2Fintro-to-custom-studio-components%2Fchangelog&fromId=95ab3f77-ac9a-4996-a129-7bdc6f495e82&fromTitle=Custom+component+for+Sanity+Studio Use bun to install the beta version of Sanity UI for Studio customization. ```bash bun add @sanity/ui@beta ``` -------------------------------- ### Custom String Validation with Undefined Check Source: https://www.sanity.io/docs/studio/validation Validates a string field, allowing undefined values and checking if the string starts with 'Brew'. This example demonstrates handling undefined inputs gracefully within custom validation. ```javascript defineField({ name: 'breweryName', type: 'string', title: 'Brewery name', validation: rule => rule.custom(name => { if (typeof name === 'undefined') { return true // Allow undefined values } // This would crash if we didn't check // for undefined values first return name.startsWith('Brew') ? 'Please be more creative' : true }).warning() }) ``` -------------------------------- ### Install Beta Sanity UI Source: https://www.sanity.io/docs/changelog/f75445eb-3c3e-4d1e-986d-71a61223aa83?from=%2Fdocs%2Fstudio%2Fintro-to-custom-studio-components%2Fchangelog&fromId=95ab3f77-ac9a-4996-a129-7bdc6f495e82&fromTitle=Custom+component+for+Sanity+Studio Install the beta version of Sanity UI if you are using it for Studio customization. ```bash npm install @sanity/ui@beta ```