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 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 --jsonkosmokrator integrations:doctor sanity --jsonkosmokrator integrations:status --json
Credentials
Authentication type: API tokenapi_token. Configure credentials once, then use the same stored profile from
scripts, coding CLIs, Lua code mode, and the MCP gateway.
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
Call Sanity Headlessly
Use the generic call form when another coding CLI or script needs a stable universal interface.
Every function below can be called headlessly. The generic form is stable across all integrations;
the provider shortcut is shorter but specific to Sanity.
sanity.sanity_query_documents
Read read
Query documents in Sanity using GROQ (Graph-Relational Object Queries). Returns matching documents with their fields.
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.