How to Add llms.txt to a Next.js Site
Next.js makes this easy: you control the whole server, so serving a llms.txt at your root is a two-minute job. You have two clean options — a static file in /public or a dynamic route handler — and this guide walks through both with copy-paste code.
Generate the content first
Whichever method you use, you need the Markdown body. Our generator inspects your live pages and drafts a structured llms.txt you can drop straight into your repo. Enter your domain, review it, and edit as needed.
Generate your file:
Option 1: A static file in /public
The public directory maps directly to your site root. A file at public/llms.txt is served, unmodified, at /llms.txt. Create the file with this Markdown structure:
# Your Product or Company > A one-sentence summary of what your > Next.js app does and who it is for. ## Docs - [Getting Started](https://yourdomain.com/docs): Setup guide. - [API Reference](https://yourdomain.com/docs/api): Endpoints. ## Product - [Features](https://yourdomain.com/features): What it does. - [Pricing](https://yourdomain.com/pricing): Plans. ## Company - [About](https://yourdomain.com/about): The team. - [Contact](https://yourdomain.com/contact): Reach us.
Commit it, deploy, and you are done. This is the right choice when the content is stable and you are comfortable editing it by hand.
Option 2: A dynamic route handler
If you would rather generate the file from your own data so it never drifts, use a Route Handler in the App Router. Create app/llms.txt/route.ts:
// app/llms.txt/route.ts
export const dynamic = "force-static"; // or omit to render per-request
export function GET() {
const body = [
"# Your Product or Company",
"",
"> A one-sentence summary.",
"",
"## Docs",
"- [Getting Started](https://yourdomain.com/docs): Setup.",
].join("\n");
return new Response(body, {
headers: { "Content-Type": "text/plain; charset=utf-8" },
});
}Because the folder is literally named llms.txt, the handler responds at /llms.txt. Set force-static for a cacheable build-time file, or read from your CMS or database at request time to keep the list current. Because Next.js APIs and conventions shift between major versions, confirm the current Route Handler signature in your installed docs before shipping.
Deployment notes
Vercel & Netlify
Both serve /public assets from the root automatically. A route handler is deployed as a serverless or edge function and mapped to the same path — no config file changes required.
Static export
With output: "export", the /public approach is bulletproof — the file is copied into the exported output. A route handler only exports cleanly if it is fully static.
Self-hosted (Node or Docker)
When you run next start behind Nginx or a load balancer, both approaches work as-is. Just make sure no upstream rule shadows the /llms.txt path before it reaches Next.js.
Verify it works
Hit the URL
Open https://yourdomain.com/llms.txt in a browser and confirm you see plain-text Markdown, not an HTML page.
Check the content type
curl -I your URL and confirm a 200 with Content-Type: text/plain. The public folder does this by default; the route handler does it via the header you set.
Confirm links resolve
Every URL in the file should return 200 on your deployed site. Broken entries undercut the file's value.
Run a visibility check
Use our AI Visibility tool to confirm the file is reachable and parseable from the public internet.
Frequently Asked Questions
Should I use the public folder or a route handler?
If your file is a fixed piece of content you edit by hand, put it in /public — it is the simplest, most cache-friendly option. If you want to generate the file from your data (a CMS, a database, or your sitemap) at build or request time, use a route handler so the content stays in sync automatically.
Do I need a route named exactly llms.txt?
For the route-handler approach, yes: create app/llms.txt/route.ts. The App Router treats the dot as part of the segment, so the file is served at /llms.txt. Return a plain Response with a text/plain content type. No page component or metadata is involved.
Does this work with static export (output: export)?
The /public approach always works, including with static export, because the file is copied verbatim into the output. A route handler that is fully static can also be exported, but if it reads request data at runtime it needs a server or edge runtime rather than a pure static export.
Will Vercel or Netlify serve the file at the root automatically?
Yes. Anything in /public is served from the deployment root on Vercel, Netlify, and most Next.js hosts, so /public/llms.txt becomes yourdomain.com/llms.txt with no extra configuration. A route handler is deployed as a serverless or edge function and mapped to the same path.
Is llms.txt guaranteed to change how AI tools use my content?
No. As of mid-2026 llms.txt is a proposed, advisory standard with no enforcement mechanism, and support varies across AI systems. There is no guarantee a given model will fetch or use it. It is a low-cost best practice, not a lever you can pull for guaranteed results.
Generate Your llms.txt for Next.js
Enter your domain and get Markdown you can drop straight into /public or a route handler.