What Next.js does today
Next.js does not create an llms.txt for your app. Its metadata file conventions cover icons, manifest.json, Open Graph images, robots.txt and sitemap.xml. There is no llms.txt convention. The nextjs.org docs site publishes its own /llms.txt, but that is the docs team's file, not a framework feature.
You have two options. Use a static file in public/ if the content changes only when you deploy. Use a Route Handler if you build the file from data.
Add llms.txt to Next.js
Option A: static file (simplest)
- Write the file in the llms.txt format: an H1 title, a one-line blockquote summary, then
##sections of links. - Save it as
public/llms.txt. The docs say files inpublicare referenced "starting from the base URL (/)", so it appears at/llms.txt. - Deploy.
Option B: Route Handler (for generated content)
- Create
app/llms.txt/route.ts. A folder name with a dot works: the Next.js docs useapp/rss.xml/route.tsfor an RSS feed. - Return a
Responseand set the content type yourself.
// app/llms.txt/route.ts
export const dynamic = 'force-static'
export async function GET() {
const text = await buildLlmsTxt() // your function
return new Response(text, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
})
}
- Decide on caching. The docs say "Route Handlers are not cached by default" (a change in Next.js 15).
export const dynamic = 'force-static'caches aGEThandler, so it runs at build time. Remove that line if the file must reflect live data. - If you enabled Cache Components (
cacheComponents: true), delete thedynamicline. The migration guide says segments that still export it "will error". It tells you to move data access into a helper marked'use cache'.
Use one option, not both. In our test with next start (16.4.0), a public/llms.txt was served and a route handler at the same path never ran. The docs do not describe this, and we did not test it on Vercel.
Check that it works
Run curl -sI https://your-site.com/llms.txt after you deploy. You want a 200 status and a text/plain content type. In our test, public/ files and the handler above both returned text/plain. The docs do not state the content type for public/ files, so check the header on your host.
Then run the llms.txt exists check against your domain, or paste the file into the llms.txt validator.
Limits and workarounds
- Proxy and middleware. The metadata docs say to configure the
proxy.tsmatcher to exclude metadata files.llms.txtis not a metadata file, but the same advice is sensible: make sure your matcher skips/llms.txt, or you may rewrite or block it. - Soft 404s. In our test, Next.js returned a real 404 for a missing
.txtpath. A catch-all page that renders for every path would answer with HTML and a 200. The audit treats an HTML page at/llms.txtas a missing file. - Caching of
public/. The docs say Next.js sendsCache-Control: public, max-age=0forpublic/files. - Reach.
llms.txtmostly helps coding agents and tools that fetch documentation, not Google or chat-assistant visibility. Link to it from your docs so agents can find it.