How to Add LLMs.txt to Next.js

Serve llms.txt from your Next.js app with zero configuration

Quick summary: Place your llms.txt file in the public/ directory. Next.js will automatically serve it at /llms.txt.

Method 1: Public Directory (App Router & Pages Router)

This is the simplest and recommended approach for both App Router and Pages Router projects.

  1. Generate your llms.txt file using our free tool
  2. Save the file as llms.txt
  3. Move it to your Next.js project's public/ directory:
your-project/
├── app/                 # or pages/ for Pages Router
├── public/
│   ├── favicon.ico
│   └── llms.txt         <-- place it here
├── next.config.js
└── package.json

That's it. Next.js automatically serves any file in public/ at the root path. Your file will be available at:

http://localhost:3000/llms.txt (development) https://yourdomain.com/llms.txt (production)

Method 2: App Router Route Handler (Dynamic)

If you want to generate or modify the llms.txt content dynamically, create a route handler:

// app/llms.txt/route.ts
import { NextResponse } from "next/server";

export async function GET() {
  const content = `# Your Site Name

## Overview
Your site description here...

## Sections
### Products
- [Page Title](https://yoursite.com/page) — Description

## Notes
Generated dynamically on 2026-05-28T03:23:18.831Z
`;

  return new NextResponse(content, {
    headers: {
      "Content-Type": "text/markdown; charset=utf-8",
      "Cache-Control": "public, max-age=3600",
    },
  });
}

This approach is useful if you want to pull content from a CMS, database, or API and regenerate the file automatically.

Method 3: Pages Router API Route

For older Next.js projects using the Pages Router:

// pages/api/llms.txt.ts
import type { NextApiRequest, NextApiResponse } from "next";

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  const content = `# Your Site Name

## Overview
Your site description...
`;

  res.setHeader("Content-Type", "text/markdown; charset=utf-8");
  res.setHeader("Cache-Control", "public, max-age=3600");
  res.status(200).send(content);
}

Then add a rewrite in next.config.js to map /llms.txt to the API route:

// next.config.js
module.exports = {
  async rewrites() {
    return [
      {
        source: "/llms.txt",
        destination: "/api/llms.txt",
      },
    ];
  },
};

Best Practices for Next.js

User-agent: *
Disallow:

LLMs-txt: https://yourdomain.com/llms.txt

Vercel Deployment Notes

If you deploy on Vercel (the company behind Next.js), the public directory method works without any additional configuration. Files in public/ are served from the edge network automatically.

For dynamic route handlers, Vercel's edge caching will respect your Cache-Control headers.

Ready to generate your file?

Generate Your LLMs.txt