---
title: "The SitecoreClient API"
slug: "the-sitecoreclient-api"
abstract: "Overview of the SitecoreClient API class used to interact with SitecoreAI headless services."
---
# The SitecoreClient API

The [`SitecoreClient` class](https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/client/classes/SitecoreClient.md) is a generic, framework-agnostic client that you can use to interact with SitecoreAI's headless APIs and services. It provides a unified interface for retrieving and managing content, layout, dictionary data, error pages, preview data, sitemaps, `robots.txt`, and other site-related information from a SitecoreAI backend, typically via GraphQL endpoints.

It enables the following:

- Content retrieval - fetch page layout data, preview data, and component data for rendering pages and components.
- Localization - retrieve dictionary phrases for specific sites and locales.
- Personalization - provide personalized content by handling variant IDs and rewriting layout data accordingly.
- SEO support - fetch sitemap XML and `robots.txt` content for SEO and crawler support.
- Static paths - generate static paths for all site pages, enabling workflows such as static site generation.
- Extensibility - implement custom services using dependency injection in the constructor.

## Configuration

To initialize the `SitecoreClient`, you need to provide a configuration object of type [`SitecoreClientInit`](https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/client/type-aliases/SitecoreClientInit.md).

The configuration object is derived from the [`SitecoreConfig` type](https://doc.sitecore.com/sai/en/developers/content-sdk/20/the-sitecore-configuration-file.html "The Sitecore configuration file"), which includes all settings necessary for connecting to SitecoreAI's headless services. It includes a `custom` property that allows you to [inject custom implementations for the services used by `SitecoreClient`](https://doc.sitecore.com/sai/en/developers/content-sdk/20/customize-sitecoreclient.html "Customize SitecoreClient").

## Key methods

Here is a list of the methods exposed by the `SitecoreClient` class, including their purpose, input parameters, and expected outputs. You can learn more about the related services by referring to the linked API documentation.

<table style="width:100%;" class="informaltable frame-void rules-rows"><thead><tr><th class="th"><p>Method name</p></th><th class="th"><p>Description</p></th><th class="th"><p>Type signature</p></th></tr></thead><tbody><tr><td class="td"><p><code class="code">getComponentData</code></p></td><td class="td"><p><span class="emphasis"><em>(Next.js only)</em></span> Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/nextjs/index/classes/ComponentPropsService.md" target="_blank" rel="noopener"><code class="code">ComponentPropsService</code></a> to parse components from the Next.js component factory with layout data, then executes the <code class="code">getComponentServicerProps</code> method and returns the resulting component props.</p></td><td class="td"><p><code class="code">getComponentData(layoutData: LayoutServiceData, context: GetServerSidePropsContext | GetStaticPropsContext, moduleFactory: ModuleFactory): Promise&lt;ComponentPropsCollection&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getDictionary</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/i18n/classes/DictionaryService.md" target="_blank" rel="noopener"><code class="code">DictionaryService</code></a> to retrieve dictionary phrases for a given site and locale.</p></td><td class="td"><p><code class="code">getDictionary(routeOptions?: Partial&lt;RouteOptions&gt;, fetchOptions?: FetchOptions): Promise&lt;DictionaryPhrases&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getErrorPage</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/site/classes/ErrorPagesService.md" target="_blank" rel="noopener"><code class="code">ErrorPagesService</code></a> to retrieve an error page for a given site and locale.</p></td><td class="td"><p><code class="code">getErrorPage(code: ErrorPage, pageOptions?: RouteOptions, fetchOptions?: FetchOptions): Promise&lt;Page | null&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getHeadLinks</code></p></td><td class="td"><p>Retrieves the head <code class="code">&lt;link&gt;</code> elements for SitecoreAI styles and themes.</p><p><code class="code">enableStyles</code> - When <code class="code">true</code>, includes content styles, CSS files associated with your Sitecore content, that are typically component-specific or content-managed stylesheets.</p><p><code class="code">enableThemes</code> - When <code class="code">true</code>, includes the Design studio/theme stylesheet links (CSS files associated with the Design studio themes). Themes provide site-wide styling and design consistency.</p></td><td class="td"><p><code class="code">getHeadLinks(layoutData: LayoutServiceData, options?: { enableStyles?: boolean; enableThemes?: boolean }): HTMLLink[]</code></p><p>Both <code class="code">enableStyles</code> and <code class="code">enableThemes</code> are <code class="code">true</code> by default.</p></td></tr><tr><td class="td"><p><code class="code">getPage</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/layout/classes/LayoutService.md" target="_blank" rel="noopener"><code class="code">LayoutService</code></a> to retrieve page data for a given route.</p></td><td class="td"><p><code class="code">getPage(path: string | string[], pageOptions?: PageOptions, fetchOptions?: FetchOptions): Promise&lt;Page | null&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getPagePaths</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/site/classes/SitePathService.md" target="_blank" rel="noopener"><code class="code">SitePathService</code></a> to retrieve the static paths of pages based on the specified languages.</p></td><td class="td"><p><code class="code">getPagePaths(languages?: string[], fetchOptions?: FetchOptions): Promise&lt;StaticPath[]&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getPreview</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/editing/classes/EditingService.md" target="_blank" rel="noopener"><code class="code">EditingService</code></a> to retrieve preview page and layout details.</p></td><td class="td"><p><code class="code">getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise&lt;Page | null&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getRobots</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/nextjs/index/classes/RobotsService.md" target="_blank" rel="noopener"><code class="code">RobotsService</code></a> to retrieve the content of the robots.txt file for a given site.</p></td><td class="td"><p><code class="code">getRobots(siteName: string, fetchOptions?: FetchOptions): Promise&lt;string | null&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getSiteMap</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/nextjs/index/classes/SitemapXmlService.md" target="_blank" rel="noopener"><code class="code">SitemapXmlService</code></a> to retrieve either an individual sitemap or a sitemap index for a given site.</p></td><td class="td"><p><code class="code">getSiteMap(options: SitemapXmlOptions, fetchOptions?: FetchOptions): Promise&lt;string&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getDesignLibraryData</code></p></td><td class="td"><p>Uses <a class="link" href="https://github.com/Sitecore/content-sdk/blob/dev/ref-docs/core/editing/classes/ComponentLayoutService.md" target="_blank" rel="noopener"><code class="code">ComponentLayoutService</code></a> to retrieve a Design studio page.</p></td><td class="td"><p><code class="code">getDesignLibraryData(designLibData: DesignLibraryRenderPreviewData, fetchOptions?: FetchOptions): Promise&lt;Page&gt;</code></p></td></tr><tr><td class="td"><p><code class="code">getData</code></p></td><td class="td"><p>Exposes a simple, typed way to run raw GraphQL requests directly from <code class="code">SitecoreClient</code>. It forwards your call to the SDK’s low-level <code class="code">GraphQLClient.request</code> with the same retry, header, and fetch behavior you’ve configured.</p><p>Examples:</p><pre class="programlisting ts" data-language="ts" id="UUID-a8a6e1bf-9af5-bc9b-82ad-dd37c86bad67_programlisting-id135237081950142"><code class="language-ts" data-language="ts">type SearchResult = { search: { results: { id: string; name: string }[] } };

const res = await client.getData&lt;SearchResult&gt;(
  `
  query SearchByName($name: String!, $lang: String!) {
    search(where: { name: { equals: $name } }, language: $lang) {
      results { id name }
    }
  }`,
  { name: 'Home', lang: 'en' }
);</code></pre><pre class="programlisting ts" data-language="ts" id="UUID-a8a6e1bf-9af5-bc9b-82ad-dd37c86bad67_programlisting-id135237082851902"><code class="language-ts" data-language="ts">import { gql } from 'graphql-tag';

const Query = gql`
  query ($lang: String!) { search(language: $lang) { results { id } } }
`;

const res = await client.getData&lt;{ search: { results: { id: string }[] } }&gt;(Query, { lang: 'en' });</code></pre></td><td class="td"><p><code class="code">getData&lt;T = unknown&gt;( query: string | import('graphql').DocumentNode, variables?: Record&lt;string, unknown&gt;, fetchOptions?: FetchOptions ): Promise&lt;T&gt;</code></p></td></tr></tbody></table>