- Developer guides
Configure llms.txt support
Content SDK Angular apps can serve an llms.txt file whose content is managed in SitecoreAI. The file provides large language models and AI agents with a curated overview of the site's content, following the llms.txt proposal.
The SDK exposes the configured content at /llms.txt with the text/markdown; charset=utf-8 content type.
This feature only serves the content configured in SitecoreAI for the resolved site. It doesn't generate llms.txt content or aggregate content automatically.
Register the Express middleware
Use createLlmsTxtMiddleware from @sitecore-content-sdk/angular in your Angular SSR server. It requires the following:
- Compatible Content SDK packages that include
createLlmsTxtMiddleware. - A Sitecore client instance.
- A list of sites (
SiteInfo[]), commonly imported from.sitecore/sites.json. llms.txtcontent configured for the site in SitecoreAI.
The Angular app template registers this middleware in src/server.ts, after the robots.txt middleware. Apps generated from a template that includes this registration require no additional server setup.
To add the endpoint to an existing app, update the SDK packages and add the following imports and registration to src/server.ts:
Register the middleware before the editing endpoints, express.static(...), and the Angular SSR handler. Otherwise, another handler can serve a static file or an Angular page instead of the configured content. Use this server-side API in server.ts, not in a browser component.
For other server endpoints, see Angular middleware.
Site resolution
For each request, the middleware resolves the site from the hostname using the supplied site list. It selects the hostname in the following order:
- The
x-forwarded-hostheader, when present. - The
hostheader, with the port removed. localhost, if neither header provides a hostname.
The selected hostname must match a site entry in the supplied list. The middleware doesn't fall back to the app's default site when no hostname matches.
For multisite apps, configure each site's hostnames in the site list so requests to different hosts resolve to the intended sites. Behind a proxy or CDN, ensure that your trusted proxy sets x-forwarded-host to the intended hostname. The middleware uses that header as supplied, without removing a port or splitting a list of hosts.
After resolving the site, the middleware calls SitecoreClient.getLlmsTxt({ siteName: site.name }) to fetch its configured content.
Responses and caching
| Situation | HTTP status | Response body |
|---|---|---|
| Content is configured for the resolved site. | 200 | The site's configured llms.txt content. |
| No content is configured for the resolved site. | 404 | # llms.txt\n\n> No llms.txt content configured for this site. |
| Fetching content throws an error. | 500 | Internal Server Error. If the issue persists, please contact Sitecore Support. |
The 500 response applies to errors caught while fetching content. An unmatched hostname fails during site resolution and isn't handled by this fetch-error response.
The middleware doesn't configure response caching or provide a revalidate option. Each request calls the Sitecore client to fetch content.
Verify the endpoint
After configuring content in SitecoreAI and starting your SSR server, request /llms.txt using a hostname that matches your site list. For example, if localhost matches the intended site and the server listens on port 4200:
Confirm that the response has status 200, the Content-Type: text/markdown; charset=utf-8 header, and the expected content. In multisite apps, repeat the check for each site's hostname.
SitecoreClient API
Call SitecoreClient.getLlmsTxt directly if you need the content outside the provided middleware, for example in a custom server endpoint:
The method returns the configured content as a string, or null when no content is configured. The underlying service queries the site's llmsTxt value through Experience Edge GraphQL.
Troubleshooting
| Symptom | Action |
|---|---|
404 with the placeholder text | Configure content for the resolved site in SitecoreAI. Check that the request hostname resolves to the intended site. |
| An Angular page or static file is returned | Move the middleware registration before express.static(...) and the SSR handler. |
| The request hostname doesn't match a site | Check the hostnames in .sitecore/sites.json and the x-forwarded-host value supplied by your proxy or CDN. |
500 with the support message | Check the server logs and the Sitecore client's connection to Experience Edge. |
To log request timing and fetch errors, enable the content-sdk:llmsTxt debug namespace. Site-resolution failures occur before this handler's request logging. See Debug logging in Content SDK apps.