Introduction To Content SDK with Sitecore AI

Hello everyone, welcome to another blogpost. This blog will cover the new sdk package released by Sitecore for Sitecore AI and how it differs from traditional JSS SDK.

The Sitecore Content SDK connects SitecoreAI content to front-end JavaScript applications. It is the successor to Sitecore JavaScript Services (JSS). SitecoreAI is the new name for XM Cloud, announced at Sitecore Symposium 2025. This post covers what the SDK offers, what changed from JSS, and how its core pieces work in version 1.x and version 2.x, based on Sitecore's official documentation.

Version at a glance: Content SDK 1.0 was the first stable release. Content SDK 2.0 was released in March 2026 and requires Next.js 16. Where an API differs between versions, both are shown below.

1. What is the Content SDK?

The SDK's APIs and services fetch SitecoreAI data and use it to build and deliver pages. Developers can:

  • Build apps locally and create custom components.
  • Push components back to SitecoreAI for marketers to use.
  • Test changes by connecting a local host to the SitecoreAI Pages visual editor.
Item Details
Current version2.x (Next.js 16 minimum)
FrameworkNext.js (Pages Router and App Router; App Router became generally available in 1.2)
Main package@sitecore-content-sdk/nextjs
CLI package@sitecore-content-sdk/cli (command: sitecore-tools)
Starter kitNext.js starter template
LicenseApache 2.0 (open source, github.com/Sitecore/content-sdk)

2. Key Features

  • Visual editing: integration with SitecoreAI Pages for editing and testing components.
  • Personalization and A/B/n testing without custom code: page variants for audience categories (for example, time zone or language) and component variants tested across percentages of visitors.
  • Multi-site support. By default, different sites can't have different default languages.
  • GraphQL utilities for content, layout data, site information, and dictionaries.
  • Built-in analytics, event tracking, and personalization.
  • Next.js support: locale-based routing, SSR, and SSG.

3. Benefits

Official figures vs JSS-based applications

Smaller bundles Fewer files Less code Starter kit on disk
49% 81% 39% 8.15 MB → <1 MB

Source: Sitecore's "Why upgrade" guide. The starter kit's footprint is about 89% smaller.

Other documented benefits

  • Faster local development and component creation.
  • Testing against live remote data before publishing.
  • Quick app generation from a starter template.
  • Faster initial loads and better Core Web Vitals from smaller bundles.
  • Explicit component mapping and leaner configuration.
  • Familiar Next.js patterns, so Next.js developers get up to speed faster.

4. What Changed: JSS vs Content SDK

Area JSS Content SDK
Next.js package@sitecore-jss/sitecore-jss-nextjs@sitecore-content-sdk/nextjs
CLI package@sitecore-jss/sitecore-jss-cli@sitecore-content-sdk/cli
Dev tools package@sitecore-jss/sitecore-jss-dev-toolsRemoved
Data accessMultiple services and pluginsSingle SitecoreClient class
ConfigurationSpread across filessitecore.config.ts (runtime) + sitecore.cli.config.ts (build/CLI)
MiddlewareSeparate middleware plugin filesOne chain: defineMiddleware (1.x) / defineProxy (2.x)
Scaffoldingjss scaffoldsitecore-tools project component scaffold

To migrate, Sitecore provides upgrade guides: JSS 22.0 → Content SDK 1.5.1 (1.x docs) and JSS 22.0 → Content SDK 2.1 (2.x docs). The core step is to replace every @sitecore-jss import with its Content SDK equivalent, then run a build or type-check to catch missing references.

5. Configuration: sitecore.config.ts

sitecore.config.ts in the app root is the central runtime configuration. Starter apps ship a lightweight version with mandatory settings only. The key properties are the same in 1.x and 2.x:

Property Environment variable
api.edge.contextIdSITECORE_EDGE_CONTEXT_ID (server)
api.edge.clientContextIdNEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID
api.edge.edgeUrlNEXT_PUBLIC_SITECORE_EDGE_URL (default https://edge-platform.sitecorecloud.io)
api.local.apiKey / apiHostNEXT_PUBLIC_SITECORE_API_KEY / NEXT_PUBLIC_SITECORE_API_HOST
defaultSiteNEXT_PUBLIC_DEFAULT_SITE_NAME
defaultLanguageNEXT_PUBLIC_DEFAULT_LANGUAGE (default 'en')
editingSecretSITECORE_EDITING_SECRET

Set exactly one of api.edge or api.local. Using separate server and client Context IDs gives data access without exposing sensitive credentials in the browser. Other settings include layout, dictionary, retries, redirects, multisite, personalize, and generateStaticPaths.

Retries and caching

  • Retries are on by default for the layout, dictionary, and error-page services. retries.count defaults to 3; set it to 0 to disable them.
  • retries.retryStrategy accepts a RetryStrategy from @sitecore-content-sdk/nextjs/client. The default, DefaultRetryStrategy, uses exponential back-off (factor 2) for HTTP 429, 502, 503, 504 and 520–524.
  • Dictionary caching (dictionary.caching) is in-memory and on by default, with a 60-second timeout.

To read config values anywhere in the app:

import scConfig from 'sitecore.config';

6. Core Architecture: SitecoreClient

SitecoreClient is a generic, framework-agnostic class for working with SitecoreAI's headless APIs. It is initialized with a SitecoreClientInit object derived from your SitecoreConfig. Its custom property lets you inject your own service implementations.

Key methods (the same in 1.x and 2.x):

Method Purpose / returns
getPage(path, pageOptions?, fetchOptions?)Page for a route (layout data). Promise<Page | null>
getPreview(previewData, fetchOptions?)Preview / editing page. Promise<Page | null>
getDictionary(routeOptions?, fetchOptions?)Promise<DictionaryPhrases>
getErrorPage(code, pageOptions?, fetchOptions?)Error page. Promise<Page | null>
getPagePaths(languages?, fetchOptions?)Static paths for SSG. Promise<StaticPath[]>
getComponentData(layoutData, context, moduleFactory)Component-level props (Next.js only)
getHeadLinks(layoutData, options?)Style/theme <link> elements (enableStyles, enableThemes)
getSiteMap(options, fetchOptions?) / getRobots(siteName, fetchOptions?)Sitemap XML and robots.txt for SEO
getDesignLibraryData(designLibData, fetchOptions?)Design Library data. Promise<Page>
getData<T>(query, variables?, fetchOptions?)Raw GraphQL request using your configured retry, header, and fetch behavior. Promise<T>

7. Components and the CLI

The CLI is configured in sitecore.cli.config.ts using defineCliConfig from @sitecore-content-sdk/nextjs/config-cli. It must be installed globally.

Scaffold a component

sitecore-tools project component scaffold ProductCard
sitecore-tools project component scaffold MyBYOCComponent --byoc
sitecore-tools project component scaffold MyComponent --templateName=myTemplate
  • Creates src/components/ProductCard.tsx from the default template for the framework.
  • Custom templates must be defined under scaffold.templates in sitecore.cli.config.ts.
  • --config points to a different CLI config file.

Build command

sitecore-tools project build

Runs the functions listed under build.commands in order (by default generateMetadata() and generateSites()) to prepare build artifacts.

Component map

The component map at .sitecore/component-map.ts maps Sitecore rendering names to components. It exports componentMap, a Map whose string keys match the component names in Sitecore.

  • Generated automatically by the build and dev scripts (sitecore-tools:generate-map).
  • Configured under componentMap in sitecore.cli.config.ts: paths (default src/components), exclude, destination (default .sitecore), componentImports, and mapTemplate.
  • Manual registration is only needed for advanced cases such as Next.js dynamic() imports. In that case, remove sitecore-tools:generate-map from the scripts.
  • App Router: two maps are generated: component-map.ts (all components, server-side) and component-map.client.ts (client components only), so server code stays out of browser bundles.

8. Middleware (1.x) and Proxy (2.x)

Request pre-processing such as multisite resolution, redirects, and personalization runs as a single chain. The API was renamed in 2.x.

  Content SDK 1.x Content SDK 2.x
Filemiddleware.tsproxy.ts
Import@sitecore-content-sdk/nextjs/middleware@sitecore-content-sdk/nextjs/proxy
Base classMiddleware (or MiddlewareBase)ProxyHandler (or ProxyBase)
Method to implementhandle(req, res)handle(req, res)
ChaindefineMiddleware(...).exec(req, ev)defineProxy(...).exec(req)

Extend MiddlewareBase / ProxyBase when you want to inherit the default Sitecore methods. With ProxyBase, your constructor must accept a ProxyBaseConfig. Handlers are passed as separate arguments, not as an array.

Custom handler: 1.x

import { defineMiddleware, Middleware } from '@sitecore-content-sdk/nextjs/middleware';
import { NextRequest, NextResponse, NextFetchEvent } from 'next/server';

class LoggerMiddleware extends Middleware {
  async handle(req: NextRequest, res: NextResponse): Promise<NextResponse> {
    console.log(`[LOGGER] ${req.method} ${req.url}`);
    return res;
  }
}

const logger = new LoggerMiddleware();

export function middleware(req: NextRequest, ev: NextFetchEvent) {
  return defineMiddleware(logger, multisite, redirects, personalize).exec(req, ev);
}

Custom handler: 2.x

import { ProxyHandler } from '@sitecore-content-sdk/nextjs/proxy';
import { NextRequest, NextResponse, NextFetchEvent } from 'next/server';

class LoggerProxy extends ProxyHandler {
  async handle(req: NextRequest, res: NextResponse): Promise<NextResponse> {
    console.log(`[LOGGER] ${req.method} ${req.url}`);
    return res || NextResponse.next();
  }
}

export function proxy(req: NextRequest, event: NextFetchEvent) {
  const logger = new LoggerProxy();
  return defineProxy(logger, multisite, redirects, personalize).exec(req);
}

multisite, redirects and personalize are the built-in handler instances already set up in the starter app's middleware.ts / proxy.ts.

Detecting editing mode

There is no official helper. As a workaround, check the Sitecore cookies sc_headless_mode and sitename#sc_mode. Next.js uses __next_preview_data (Preview Mode, Pages Router) and __prerender_bypass (Draft Mode, App Router).

9. Key Takeaways

  • Officially 49% smaller bundles, 81% fewer files and 39% less code than JSS, with a starter kit under 1 MB.
  • One SitecoreClient (getPage, getDictionary, getData, and more) replaces JSS's separate services.
  • Configuration lives in two files: sitecore.config.ts and sitecore.cli.config.ts.
  • Retries (3, exponential back-off) and dictionary caching (60 s) are on by default.
  • The component map is generated automatically; App Router gets separate server and client maps.
  • Middleware in 1.x (defineMiddleware) became Proxy in 2.x (defineProxy, proxy.ts).
  • Content SDK 2.x requires Next.js 16.

References

Comments

Popular posts from this blog

Switching Docker Desktop to Docker CLI in Easy Way

My Sitecore Upgrade Learnings Part 1

Steps to Generate Access Token for Authoring API Endpoint in XM Cloud