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.
This is the simplest and recommended approach for both App Router and Pages Router projects.
llms.txtpublic/ 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:
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.
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",
},
];
},
};Content-Type: text/markdown so AI crawlers recognise the format.User-agent: * Disallow: LLMs-txt: https://yourdomain.com/llms.txt
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.