data
Sanity CLI for AI Agents
Use the Sanity CLI from KosmoKrator to call Sanity tools headlessly, return JSON, inspect schemas, and automate workflows from coding agents, scripts, and CI.Sanity CLI Setup
Sanity can be configured headlessly with `kosmokrator integrations:configure sanity`.
# Install KosmoKrator first if it is not available on PATH.
curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash
# Configure and verify this integration.
kosmokrator integrations:configure sanity --set api_token="$SANITY_API_TOKEN" --set project_id="$SANITY_PROJECT_ID" --enable --read allow --write ask --json
kosmokrator integrations:doctor sanity --json
kosmokrator integrations:status --json Credentials
Authentication type: API token api_token. Configure credentials once, then reuse the same stored profile from scripts, coding CLIs, Lua, and MCP.
| Key | Env var | Type | Required | Label |
|---|---|---|---|---|
api_token | SANITY_API_TOKEN | Secret secret | yes | API Token |
project_id | SANITY_PROJECT_ID | Text text | yes | Project ID |
dataset | SANITY_DATASET | Text text | no | Dataset |
Command Patterns
The generic command is stable across every integration. The provider shortcut is shorter for humans.
kosmo integrations:call sanity.sanity_query_documents '{"query":"example_query","params":"example_params"}' --json kosmo integrations:sanity sanity_query_documents '{"query":"example_query","params":"example_params"}' --json Discovery
These commands return structured output for coding agents that need to inspect capabilities before choosing a function.
kosmo integrations:docs sanity --json
kosmo integrations:docs sanity.sanity_query_documents --json
kosmo integrations:schema sanity.sanity_query_documents --json
kosmo integrations:search "Sanity" --json
kosmo integrations:list --json Automation Contexts
The same configured command surface works in these environments. The command does not change unless the host wrapper, credentials, or permissions change.
CLI Functions
Every function below can be called headlessly. Commands are highlighted, copyable, and scroll horizontally when payloads are long.
sanity.sanity_query_documents
Query documents in Sanity using GROQ (Graph-Relational Object Queries). Returns matching documents with their fields.
read - Parameters
- query, params
kosmo integrations:call sanity.sanity_query_documents '{"query":"example_query","params":"example_params"}' --json kosmo integrations:sanity sanity_query_documents '{"query":"example_query","params":"example_params"}' --json sanity.sanity_get_document
Retrieve a single Sanity document by its ID. Returns the full document with all fields.
read - Parameters
- id
kosmo integrations:call sanity.sanity_get_document '{"id":"example_id"}' --json kosmo integrations:sanity sanity_get_document '{"id":"example_id"}' --json sanity.sanity_create_document
Create a new document in the Sanity dataset. The document data must include a _type field matching a schema type.
write - Parameters
- document
kosmo integrations:call sanity.sanity_create_document '{"document":"example_document"}' --json kosmo integrations:sanity sanity_create_document '{"document":"example_document"}' --json sanity.sanity_update_document
Update an existing Sanity document by applying a patch with the specified fields.
write - Parameters
- id, set
kosmo integrations:call sanity.sanity_update_document '{"id":"example_id","set":"example_set"}' --json kosmo integrations:sanity sanity_update_document '{"id":"example_id","set":"example_set"}' --json sanity.sanity_delete_document
Delete a document from the Sanity dataset by its ID. This action is permanent.
write - Parameters
- id
kosmo integrations:call sanity.sanity_delete_document '{"id":"example_id"}' --json kosmo integrations:sanity sanity_delete_document '{"id":"example_id"}' --json sanity.sanity_list_projects
List all Sanity projects accessible to the authenticated user. Requires a management API token.
read - Parameters
- none
kosmo integrations:call sanity.sanity_list_projects '{}' --json kosmo integrations:sanity sanity_list_projects '{}' --json sanity.sanity_get_current_user
Get the currently authenticated Sanity user. Useful for verifying credentials and checking user identity.
read - Parameters
- none
kosmo integrations:call sanity.sanity_get_current_user '{}' --json kosmo integrations:sanity sanity_get_current_user '{}' --json Function Schemas
Use these parameter tables when building CLI payloads without calling integrations:schema first.
sanity.sanity_query_documents 2 parameters
kosmo integrations:schema sanity.sanity_query_documents --json | Parameter | Type | Required | Description |
|---|---|---|---|
query | string | yes | GROQ query string (e.g., `*[_type == "post"]`). See https://www.sanity.io/docs/groq for syntax. |
params | object | no | Optional parameters referenced in the query as $paramName (e.g., `{"type": "post"}` used as `*[_type == $type]`). |
sanity.sanity_get_document 1 parameters
kosmo integrations:schema sanity.sanity_get_document --json | Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The document ID (e.g., "post-123" or a draft ID like "drafts.post-123"). |
sanity.sanity_create_document 1 parameters
kosmo integrations:schema sanity.sanity_create_document --json | Parameter | Type | Required | Description |
|---|---|---|---|
document | object | yes | Document data as a JSON object. Must include a "_type" field (e.g., {"_type": "post", "title": "Hello", "body": "World"}). |
sanity.sanity_update_document 2 parameters
kosmo integrations:schema sanity.sanity_update_document --json | Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The document ID to update (e.g., "post-123"). |
set | object | yes | Fields to update as a JSON object (e.g., {"title": "Updated Title", "published": true}). Only the specified fields are changed. |
sanity.sanity_delete_document 1 parameters
kosmo integrations:schema sanity.sanity_delete_document --json | Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | The document ID to delete (e.g., "post-123"). |
sanity.sanity_list_projects 0 parameters
kosmo integrations:schema sanity.sanity_list_projects --json | Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
sanity.sanity_get_current_user 0 parameters
kosmo integrations:schema sanity.sanity_get_current_user --json | Parameter | Type | Required | Description |
|---|---|---|---|
| No parameters. | |||
Permissions
Headless calls still follow the integration read/write permission policy. Configure read/write defaults with
integrations:configure. Add --force only for trusted automation that should bypass that policy.