How to add llms.txt to a Next.js site

Next.js has no llms.txt feature. Put the file in public/ or serve it from an app/llms.txt route handler, then check the status and content type.

Next.js · llms.txt · Not built in

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)

  1. Write the file in the llms.txt format: an H1 title, a one-line blockquote summary, then ## sections of links.
  2. Save it as public/llms.txt. The docs say files in public are referenced "starting from the base URL (/)", so it appears at /llms.txt.
  3. Deploy.

Option B: Route Handler (for generated content)

  1. Create app/llms.txt/route.ts. A folder name with a dot works: the Next.js docs use app/rss.xml/route.ts for an RSS feed.
  2. Return a Response and 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' },
  })
}
  1. 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 a GET handler, so it runs at build time. Remove that line if the file must reflect live data.
  2. If you enabled Cache Components (cacheComponents: true), delete the dynamic line. 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.ts matcher to exclude metadata files. llms.txt is 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 .txt path. A catch-all page that renders for every path would answer with HTML and a 200. The audit treats an HTML page at /llms.txt as a missing file.
  • Caching of public/. The docs say Next.js sends Cache-Control: public, max-age=0 for public/ files.
  • Reach. llms.txt mostly 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.

How common is it on Next.js?

Among 333 measured Next.js sites, the median w2agent Score is 56/100.

  • llms.txt exists: 86% of 333 Next.js sites pass
  • llms.txt follows spec: 95% of 287 Next.js sites pass
  • llms.txt links resolve: 62% of 287 Next.js sites pass

Latest audit of each measured site. Sites where a check did not apply are left out.

Related checks

Check it

Test your file with the llms.txt validator.

Check your own site →

Sources

Verified against these sources on