Tech & Tools

Sanity CMS: The Complete Guide to This API-First Headless CMS

Sanity CMS is an API-first headless CMS with GROQ queries, real-time collaboration, and Portable Text - compared against WordPress, Contentful, Decap, and Payload.

Sanity CMS: The Complete Guide to This API-First Headless CMS


1. What Is Sanity?

Sanity is an API-first headless CMS - meaning it handles content management and storage, while your frontend (built in Next.js, Nuxt, SvelteKit, or anything else) fetches and displays that content however you want.

Founded in 2017 in Oslo, Norway. Today it’s one of the most widely adopted headless CMS platforms in the React and Next.js ecosystem.

Three Architectural Pillars

Content Lake

Sanity’s hosted cloud storage layer:

  • Not a traditional database - it’s a real-time document store built on JSON
  • Maintains separate draft and published states, with automatic revision history
  • Real-time sync lets multiple editors work on the same document simultaneously, Google Docs style

GROQ (Graph-Relational Object Queries)

Sanity’s own open-source query language, designed specifically for JSON documents:

*[_type == "post" && publishedAt < now()] | order(publishedAt desc) [0...10] {
  title,
  slug,
  "authorName": author->name,
  "categoryTitles": categories[]->title,
  body
}

The -> operator dereferences (joins) to another document, solving the N+1 query problem in a single request. It supports projection, filtering, sorting, slicing, and aggregation.

Sanity Studio

The content editing interface - a React app you host yourself (or deploy to Sanity’s own hosting). Configured entirely through TypeScript in sanity.config.ts. Can be embedded directly inside a Next.js app, no separate deployment required.


2. Notable Features

Real-Time Collaboration Multiple editors can work on the same document at once. You see each other’s cursors. Conflicts are resolved automatically at the field level - not at the document level like most systems.

Portable Text Rather than storing rich text as raw HTML (like WordPress does), Sanity stores it as structured JSON. This means the same content can be rendered across web, mobile, PDF, email, or any other surface without format conversion.

Image Pipeline CDN On-the-fly image transformations via URL parameters - no separate Cloudinary account needed for basic operations:

  • ?w=800&h=600 - resize
  • ?fm=webp&q=75 - convert format and adjust quality

Recent Additions (2024-2026)

  • Content Releases: Bundle multiple content changes into a single atomic publish
  • Visual Editing: Click-to-edit overlays directly on your frontend
  • AI Assist: Generate, translate, or transform content using LLM integration
  • TypeGen: Auto-generate TypeScript types from your schema and GROQ queries

3. Pricing (2025-2026)

TierPriceUsersAPI/CDN Requests
Free$0/month3500K/month
Growth~$15/user/monthUnlimited2.5M included
EnterpriseCustomUnlimitedCustom

The free tier is genuinely usable - many small production sites run comfortably within its limits.


4. How Sanity Compares

Sanity vs. WordPress

CriteriaSanityWordPress
ArchitectureHeadless, cloud-hostedMonolithic (PHP + MySQL)
Real-time collaborationNativeNone (lock-based editing)
Rich text storagePortable Text (JSON)TinyMCE/Gutenberg (HTML)
Plugin ecosystem~200+60,000+
Learning curveHigh (requires developer setup)Low (GUI-based)

Sanity vs. Decap CMS

See also: Decap CMS

CriteriaSanityDecap CMS
StorageContent Lake (Sanity cloud)Git repo (Markdown/JSON files)
Real-time collaborationYesNo (merge-based)
Vendor lock-inModerateNone (data lives in Git)
CostFree tier + paid plansCompletely free

Sanity vs. Payload CMS

CriteriaSanityPayload CMS
ArchitectureCloud (Content Lake)Self-hosted, Next.js native
DatabaseProprietaryMongoDB or PostgreSQL
Vendor lock-inModerateNone
PricingFree tier + paidFree (open source)

5. When Sanity Makes Sense

Sanity is the right choice when:

  • You’re delivering content to multiple channels - web, mobile app, kiosk, email newsletter - from a single source
  • You’re running a complex editorial operation - newsroom, magazine - with multiple simultaneous editors
  • You’re building in the Next.js/React ecosystem and want tight native integration

Sanity is probably overkill when:

  • Your team has no developer support
  • You’re running a simple blog or brochure site - Ghost or plain Markdown files will serve you better
  • Vendor lock-in is a significant concern for your organization

6. Schema Definition Example (TypeScript)

// schemas/post.ts
import { defineType, defineField } from 'sanity'

export default defineType({
  name: 'post',
  title: 'Blog Post',
  type: 'document',
  fields: [
    defineField({
      name: 'title',
      type: 'string',
      validation: (Rule) => Rule.required().max(100),
    }),
    defineField({
      name: 'slug',
      type: 'slug',
      options: { source: 'title' },
    }),
    defineField({
      name: 'body',
      type: 'array',
      of: [{ type: 'block' }, { type: 'image' }], // Portable Text
    }),
  ],
})

FAQ

Is Sanity truly headless - can I use it with any frontend?

Yes. Sanity exposes your content through a GROQ API (and a GraphQL API if you prefer). Any frontend that can make HTTP requests can consume it - Next.js, Astro, SvelteKit, a mobile app, or even a static site that fetches at build time. There’s no frontend coupling.

What happens to my content if I stop paying for Sanity?

You can export all your content via the Sanity CLI at any time using sanity dataset export. The output is a JSON file containing all your documents. It’s not a completely frictionless migration, but your data is never truly locked away.

How hard is GROQ to learn compared to SQL?

GROQ has a smaller surface area than SQL, and the syntax reads fairly naturally once you’re comfortable with it. If you already know SQL, the concepts (filtering, ordering, projection) are familiar - the syntax is just different. Most developers get productive with GROQ within a few hours.

Can I self-host Sanity?

Sanity Studio (the editor interface) can be self-hosted. The Content Lake (the database) cannot - it’s Sanity’s proprietary hosted service. This is the primary form of vendor lock-in with Sanity.

✦ Miễn phí

Muốn nhận thêm kiến thức như thế này?

Mình tổng hợp AI, marketing và tech insights mỗi tuần - gọn, có gu.

Không spam. Unsubscribe bất cứ lúc nào.