# [llms.txt](https://rebilder.com/docs/llms-txt)

> Generate a consistent llms.txt directory from your gateway configuration, with links to your catalog, policies and other pages.

- **Updated:** 2026-08-12
- **Author:** Rebilder
- **Section:** Concepts
- **Description:** Generate a consistent llms.txt directory from your gateway configuration, with links to your catalog, policies and other pages.
- **Publisher:** Rebilder

## How llms.txt fits your setup

> **Pair your directory with readable pages** An llms.txt file provides a directory of useful pages. Keep the links current and make sure the pages themselves contain accessible, accurate business information.

## generateLlmsTxt

`generateLlmsTxt(config, options)` (root export of `@rebilder/gateway`) produces spec-shaped markdown (H1 site name, blockquote description, H2 sections of link lists) **deterministically, with injected values only, no LLM anywhere**. Same input → same output, which is why it’s safe to cache hard.

- If `config.sources.catalog` enumerates for `new URL(options.baseUrl)`, a `## Products` section (title, URL, price note) is generated automatically. Likewise `config.sources.policies` → `## Policies`.
- Sources may return `null` or throw for the base URL; both are tolerated as "nothing to list". A malformed price omits its note rather than breaking the file or emitting a wrong value.
- `options.sections` appends manual sections after the auto-generated ones, in order. Sections with no links are omitted.

| Option | Type | Notes |
| --- | --- | --- |
| `baseUrl` | `string` | The store’s canonical base URL. Catalog/policy sources are called with `new URL(baseUrl)` to enumerate site-wide entries, so wire them to return the full list for the base URL if you want auto sections. |
| `siteName` | `string` | The H1. Injected verbatim. |
| `description` | `string` | One-line description, rendered as the blockquote. Injected verbatim. |
| `sections` | `LlmsTxtSection[]` (optional) | Manual sections: `{ title, links: [{ title, url, note? }] }`. Links render as `- [title](url): note`. |

## Next.js route helper

app/llms.txt/route.ts

```
// app/llms.txt/route.ts
import { createLlmsTxtRouteHandler } from '@rebilder/gateway/next'
import { gatewayConfig } from '../../lib/gateway-config'

export const GET = createLlmsTxtRouteHandler(gatewayConfig, {
  baseUrl: 'https://store.example.com',
  siteName: 'Acme Outdoors',
  description: 'Trail footwear and gear, shipped from Bend, OR.',
  sections: [{ title: 'Guides', links: [{ title: 'Sizing guide', url: 'https://store.example.com/pages/sizing' }] }],
})
```

The route handler serves `text/plain; charset=utf-8` with long shared-cache headers (`public, max-age=300, s-maxage=3600, stale-while-revalidate=86400`), which is safe because the output is deterministic. rebilder.com serves its own at [/llms.txt](/llms.txt).

On other stacks, call `generateLlmsTxt(config, options)` yourself and serve the string from any route with the same content type.