canonical: https://jentic.com/apis/sanity.io/sanity-export

# Sanity Export HTTP Endpoint

The Sanity Export API streams every non-deleted document in a dataset as newline-delimited JSON, including drafts, release versions, and asset documents the caller can access. The export reflects the dataset as it was when the request started, and the types parameter narrows it to specific document types such as post, author, or sanity.imageAsset. For large datasets, cursor mode returns documents ordered by _id in time-boxed batches that end with a nextCursor object to resume from. An error after streaming begins keeps the 200 status and ends the stream with an error object, so the last line must be checked before an export counts as complete.

## For AI agents

Stream all documents in a Sanity dataset as NDJSON, filtered by document type, with cursor mode to resume large exports.

## Scope

Does not download asset files, import documents, or restore backups. Use for streaming a Sanity dataset's documents as NDJSON only.

## Capabilities

- Stream every non-deleted document in a dataset as NDJSON with exportDataset
- Limit the export to exact document types with types, adding sanity.imageAsset or sanity.fileAsset to include asset documents
- Resume large exports in cursor mode by passing the nextCursor value from the previous stream
- Detect a failed export by checking the last NDJSON line for an error object
- Include drafts, release versions, and system documents by sending a token that can read them

## Use cases

### AI agent content snapshot

An agent analysing or migrating a site's content often needs the whole dataset in one pass. Through Jentic the agent searches for 'export a Sanity dataset', loads the exportDataset operation, and requests the dataset with the types it needs while the Sanity token is injected at call time. It then checks the final line for an error object or a nextCursor before treating the export as done.

Example prompt: GET `/data/export/production` with types post,author and read the NDJSON stream, then confirm the last line has no error key

### Resumable export of a large dataset

Datasets with tens of thousands of documents can time out mid-stream. Setting nextCursor to an empty string starts cursor mode, where each request runs for up to 30 seconds and ends with a nextCursor object, and the export is complete when a stream ends with neither a nextCursor nor an error object.

Example prompt: GET `/data/export/production` with nextCursor set to an empty string, then repeat with each returned nextCursor until a stream ends without one

### Typed exports for migration

Moving one content type to another system rarely needs the full dataset. The types parameter takes a comma-separated list of exact _type values, with no wildcards, so a migration can pull just articles and their image asset documents.

Example prompt: GET `/data/export/production` with types article,sanity.imageAsset and save the stream as an .ndjson file

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| GET | `/data/export/{dataset}` | Export documents in a dataset as NDJSON |

## Key resources

- **Documents** — Every non-deleted document in the dataset, including drafts, release versions, and asset documents
- **Export cursor** — A nextCursor object marking where a cursor-mode export should resume

## AI readiness

This API is usable in Jentic One now. Its AI-readiness score against Jentic's framework shows where it stands today and where improvements would make it even easier for agents to use.

- **Score:** 69 / 100
- **Maturity:** AI-Aware
- **Dimensions:**
  - Foundational Compliance: 100 / 100
  - Developer Experience & Jentic Compatibility: 72 / 100
  - AI-Readiness & Agent Experience: 57 / 100
  - Agent Usability: 94 / 100
  - Security: 60 / 100
  - AI Discoverability: 50 / 100
- **View full report:** https://jentic.com/apis/sanity.io/sanity-export/scorecard
- **How the score is calculated:** https://docs.jentic.com/reference/api-readiness-framework/overview/
- **More about the dimensions:** https://docs.jentic.com/reference/api-readiness-framework/specification/#dimensional-model-overview

### Score it yourself

Every API in the directory is allowlisted, so you can re-score it with no key required.

- **Score your own API:** https://jentic.com/scorecard.md
- **Scoring CLI agent skill:** https://github.com/jentic/jentic-api-scorecard/blob/main/skills/jentic-api-scorecard/SKILL.md

```sh
npx @jentic/api-scorecard-cli score <openapi-url>
```

## Why Jentic

- **Setup:** Wiring the Sanity Export API by hand means templating the projectId and apiVersion into the host, parsing an NDJSON stream, following nextCursor in cursor mode, and checking the final line for an error object. Through Jentic you install once, import it from the API Directory, store the token once, and your agent calls it.
- **Permission scoping:** Sanity puts the dataset in the URL path (`/data/export/{dataset}`), so a rule can pin your agent to exporting one dataset such as staging. The single operation is a read, and the token's own access decides whether drafts and release versions are included.
- **Credential handling:** Your Sanity token is stored once, encrypted, by your own Jentic One instance and injected at execution time. It never enters the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'export a Sanity dataset' or 'download all Sanity documents', and Jentic returns the exportDataset operation with its types and nextCursor parameters.

## Related APIs

- **Sanity Backups API** — List and download dataset backups
- **Sanity Copy API** — Clone a dataset inside Sanity's cloud
- **Sanity HTTP API** — Query documents with GROQ and write mutations
- **Contentful** — Headless CMS with entries and assets

## FAQ

### What authentication does the Sanity Export API use?

Per its OpenAPI spec, the Sanity Export API accepts a bearer token in the Authorization header, and the token is optional. Without one, the export contains only publicly available documents, and a private dataset returns 200 with an empty stream. With a token, it contains the documents that token can access; through Jentic the token is stored by your own instance and attached at call time.

### How do I know a Sanity export completed?

Check the last line of the stream. If an error happens after the first document, the status stays 200 and the stream ends with an error object. In cursor mode, a trailing nextCursor object means more documents remain; the export is complete when a stream ends with neither.

### Should I use the Export API or the Sanity CLI?

The spec recommends the sanity datasets export CLI command or the @sanity/export npm package in most cases, since they download assets, can exclude drafts, and follow cursors for you. Use the HTTP endpoint when you need the raw NDJSON stream directly.

### What are the rate limits for the Sanity Export API?

The OpenAPI spec does not specify rate limits. In cursor mode each request runs for up to 30 seconds before returning a cursor. Check https://www.sanity.io/docs for current API limits for your plan.

### Is there a Sanity Export MCP server?

You don't need an MCP server to give your agent the Sanity Export API. Jentic connects it directly from the API Directory: import it, store your Sanity token once, and your agent calls exportDataset when it needs a dataset snapshot.

### How do I export a Sanity dataset through Jentic?

Search Jentic for 'export a Sanity dataset', load the exportDataset operation, and execute GET `/data/export/{dataset}`, optionally with types and nextCursor. To run it on your own infrastructure, install Jentic One from its GitHub repo.

### Can I limit what my agent is allowed to do with the Sanity Export API?

Yes. A rule that allows only GET `/data/export/staging` lets the agent pull full snapshots of staging while the production dataset stays out of reach. The operation is read-only, and every call it makes is logged.
