llms.txt Kit

How to Add & Validate llms.txt in Next.js

llms.txt
Line 1, Col 1
Valid Spec
0
Est. Tokens
0
Words
Links
0
Sections
llms.txt Sweet Spot (4k max)
0 / 4,000 (0%) Optimal Size
GPT-4o 0.00% / Claude 3.7 0.00% / Gemini 2.5 0.000%

Specification Linter Diagnostics

0 errors · 0 warnings
Next.js Integration

Serving llms.txt in Next.js: Static File vs. Route Handler

Next.js makes serving a spec-compliant /llms.txt straightforward whether you use Static Export, Pages Router, or the App Router. Validate your draft in the editor above first so your headings, blockquote summary, and token budget stay clean.

Method 1: Static File in public/llms.txt (Fastest)

Download llms.txt from the editor above and save it directly to public/llms.txt. Next.js automatically serves it at https://yourdomain.com/llms.txt without any routing configuration.

Method 2: Dynamic App Router Handler (app/llms.txt/route.ts)

If your documentation or blog updates frequently from MDX or a CMS, serve /llms.txt dynamically with caching headers:

export const revalidate = 3600;

export async function GET() {
  const body = [
    '# Your Project Name',
    '',
    '> Concise summary of your Next.js documentation and product.',
    '',
    '## Documentation',
    '- [Quickstart](https://yourdomain.com/docs/quickstart): Install and deploy in 5 minutes.',
  ].join('\n');

  return new Response(body, {
    headers: { 'Content-Type': 'text/plain; charset=utf-8' },
  });
}
Frequently Asked Questions

llms.txt for Next.js Guide FAQ

Should I use public/llms.txt or app/llms.txt/route.ts in Next.js?

Use public/llms.txt for mostly static docs or marketing sites because it is served directly from CDN edge cache with zero function invocations. Use app/llms.txt/route.ts only when links change dynamically from a database or CMS.

Does Next.js middleware interfere with /llms.txt?

If you run i18n or auth middleware in middleware.ts, make sure your matcher excludes llms.txt (e.g., (?!api|_next|llms\.txt|robots\.txt|sitemap\.xml)) so crawlers are not redirected.

How do I verify my Next.js llms.txt headers?

Run curl -I https://yourdomain.com/llms.txt and verify it returns HTTP 200 and Content-Type: text/plain; charset=utf-8.

AI Crawler Rules & Framework Integration Guides

Explore dedicated robots.txt generators and platform-specific llms.txt deployment templates:

Copied!