How to Add llms.txt to Next.js

Publish a root llms.txt in Next.js with an App Router Route Handler and verify the response after deploy.

Try

Setup steps

  1. Create app/llms.txt/route.ts

    If your project uses src/app, put the handler there. Update the sample links to point to your public pages.

    Create app/llms.txt/route.ts example
    export const dynamic = "force-static";
    
    export function GET() {
      const body = "# Example Site\n\n> Product documentation and support for Example Site.\n\n## Documentation\n- [Getting started](https://example.com/docs): Setup steps for new users.\n- [Support](https://example.com/support): Find help and contact details.\n";
      return new Response(body, {
        headers: { "Content-Type": "text/markdown; charset=utf-8" },
      });
    }
  2. Deploy and test the public route

    Deploy the change and request /llms.txt on the production hostname. If you use the public folder instead, place llms.txt there and keep a single implementation for that path.

Official platform documentation

Verify the published llms.txt

Replace example.com with the published hostname and fetch the file. The final response should be HTTP 200 with the expected Markdown body and a Content-Type of text/markdown; charset=utf-8 or text/plain; charset=utf-8.

HTTP verification command
curl -fsSL -i https://example.com/llms.txt

If status 200 comes back with an HTML homepage, sign-in screen or error page, you have an HTML fallback (a soft 404). Check the final URL and fix the route or rewrite, then fetch it again.

Frequently asked questions

Can I use public/llms.txt instead?

Yes. Next.js serves files in public at the site root. The Route Handler gives you direct control over the response headers.

What if my app uses src/app?

Create src/app/llms.txt/route.ts inside your existing App Router directory.

Why does my /llms.txt return a page with status 200?

A rewrite or fallback may serve your app shell. Inspect the final Content-Type and body, then route /llms.txt to the handler ahead of the fallback.

Scan your published site

Check the live page and its robots.txt and llms.txt. The scan is free. If you want files tailored to the report, the $12 Auto-Generated Fix Pack is available from the results.

Run a free scan