KosmoKrator

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, configure, and verify
# 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.

KeyEnv varTypeRequiredLabel
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.

Generic CLI call
kosmo integrations:call sanity.sanity_query_documents '{"query":"example_query","params":"example_params"}' --json
Provider shortcut
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.

Discovery commands
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 read
Parameters
query, params
Generic call
kosmo integrations:call sanity.sanity_query_documents '{"query":"example_query","params":"example_params"}' --json
Shortcut
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 read
Parameters
id
Generic call
kosmo integrations:call sanity.sanity_get_document '{"id":"example_id"}' --json
Shortcut
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 write
Parameters
document
Generic call
kosmo integrations:call sanity.sanity_create_document '{"document":"example_document"}' --json
Shortcut
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 write
Parameters
id, set
Generic call
kosmo integrations:call sanity.sanity_update_document '{"id":"example_id","set":"example_set"}' --json
Shortcut
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 write
Parameters
id
Generic call
kosmo integrations:call sanity.sanity_delete_document '{"id":"example_id"}' --json
Shortcut
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 read
Parameters
none
Generic call
kosmo integrations:call sanity.sanity_list_projects '{}' --json
Shortcut
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 read
Parameters
none
Generic call
kosmo integrations:call sanity.sanity_get_current_user '{}' --json
Shortcut
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
Schema command
kosmo integrations:schema sanity.sanity_query_documents --json
ParameterTypeRequiredDescription
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
Schema command
kosmo integrations:schema sanity.sanity_get_document --json
ParameterTypeRequiredDescription
id string yes The document ID (e.g., "post-123" or a draft ID like "drafts.post-123").
sanity.sanity_create_document 1 parameters
Schema command
kosmo integrations:schema sanity.sanity_create_document --json
ParameterTypeRequiredDescription
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
Schema command
kosmo integrations:schema sanity.sanity_update_document --json
ParameterTypeRequiredDescription
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
Schema command
kosmo integrations:schema sanity.sanity_delete_document --json
ParameterTypeRequiredDescription
id string yes The document ID to delete (e.g., "post-123").
sanity.sanity_list_projects 0 parameters
Schema command
kosmo integrations:schema sanity.sanity_list_projects --json
ParameterTypeRequiredDescription
No parameters.
sanity.sanity_get_current_user 0 parameters
Schema command
kosmo integrations:schema sanity.sanity_get_current_user --json
ParameterTypeRequiredDescription
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.