- Developer guides
Configure llms.txt support
Content SDK Next.js apps can serve an llms.txt file whose content is managed via SitecoreAI configuration. The SDK is responsible for exposing the content at the /llms.txt path; SitecoreAI is responsible for generating and storing the llms.txt content itself.
llms.txt is served with the text/markdown; charset=utf-8 content type, per the llms.txt specification.
This feature only serves the content configured in SitecoreAI for the resolved site. It doesn't generate llms.txt content, and it doesn't aggregate content automatically.
Route handler for App Router
Use createLlmsTxtRouteHandler from @sitecore-content-sdk/nextjs/route-handler to scaffold the GET implementation. It requires the following:
- A Sitecore client instance
- A list of sites (
SiteInfo) (commonly imported from.sitecore/sites.json)
See the following example in app/api/llms-txt/route.ts:
You must also define a Next.js rewrite in next.config.ts so the handler responds at the canonical /llms.txt path:
The handler resolves the site from the incoming Host header, the same way robots.txt and sitemap.xml route handlers do.
Caching and revalidation
By default, responses are cached for 60 seconds. To adjust or disable revalidation:
- Pass a number (seconds) to set a new duration.
- Pass
falseto skip revalidation and cache indefinitely (only do this if content is truly static). - Omit
revalidateto use the default.
See the following example with a custom duration:
No content configured
When no llms.txt content is configured for the resolved site, the handler returns a 404 response with default placeholder content, so the route always returns a valid llms.txt document instead of an empty response.
Middleware for Pages Router
For Pages Router apps, use LlmsTxtMiddleware from @sitecore-content-sdk/nextjs/middleware in an API route.
See the following example in pages/api/llms-txt.ts:
You must also define a rewrite in next.config.js as shown:
The Pages Router middleware doesn't cache responses; each request fetches the current content from SitecoreAI.
SitecoreClient API
Both the Route Handler and the middleware use SitecoreClient.getLlmsTxt:
Call this method directly if you need the llms.txt content outside of the provided Route Handler or middleware, for example in a custom route.
Related packages and exports
@sitecore-content-sdk/content/siteexportsLLMS_TXT_CONTENT_TYPEandDEFAULT_LLMS_TXTfor use in custom implementations.@sitecore-content-sdk/nextjs/route-handlerexportscreateLlmsTxtRouteHandler.@sitecore-content-sdk/nextjs/middlewareexportsLlmsTxtMiddleware.