Option 1: a static file
Put llms.txt in the public/ folder. Next.js serves everything in public/ from the site root, so it answers at /llms.txt with no code. Build the Markdown with the llms.txt generator.
Option 2: an App Router route handler
To build the file from your content, create app/llms.txt/route.ts:
import { getGuides } from '@/lib/content';
export const dynamic = 'force-static';
export async function GET() {
const guides = await getGuides();
const body = [
'# Example Docs',
'',
'> Documentation for the Example API.',
'',
'## Guides',
...guides.map(g => `- [${g.title}](https://example.test${g.path}): ${g.summary}`)
].join('\n');
return new Response(body, {
headers: { 'content-type': 'text/plain; charset=utf-8' }
});
}
force-static renders it once at build time; remove it to rebuild on each request. Do not also keep a public/llms.txt: a file in public/ and a route at the same path conflict.
Check it
- Request
/llms.txtand confirm a 200 with atext/plaincontent type. - Check middleware does not redirect it, for example to a locale prefix.
- Run the AI crawler check to confirm robots.txt lets AI agents read it.
Shipwork checks whether /llms.txt exists and is served as text, alongside AI crawler access in robots.txt. Free, no account, no signup. Paste your store address.
Generate an llms.txtQuestions
Where do I put llms.txt in Next.js?
Should llms.txt be text/plain?
Does it work with the Pages Router?
Keep reading