How to Add LLMs.txt to Next.js
There are several ways to add an LLMs.txt file to a Next.js website. The best method depends on how often your content changes.
For most websites, using a static file is the easiest solution. If your content updates regularly from a CMS or database, a dynamic method may be better.
Method 1: Add a Static LLMs.txt File (Recommended)
This is the easiest option and works for most websites.
Next.js automatically serves files placed inside the /public folder. No extra setup is needed.
Step 1: Generate Your LLMs.txt File
Use the free LLMs.txt Generator to create your file.
Enter your website URL, generate the file, and download it.
Step 2: Upload the File
Place the downloaded file in:
/public/llms.txt
Step 3: Deploy Your Website
After deployment, your file will be available at:
https://yourdomain.com/llms.txt
That’s all you need to do.
No routing changes or special configuration are required.
Best For
- Blogs
- Business websites
- Portfolio sites
- Small and medium websites
- Sites that do not change often
Method 2: Create a Dynamic LLMs.txt Route
If your website content changes frequently, you may want to generate the file automatically.
A dynamic route can create the LLMs.txt file whenever someone visits the URL.
Step 1: Create a Route File
Create the following file:
app/llms.txt/route.js
Add code that returns your LLMs.txt content as plain text.
Step 2: Build Content Dynamically
You can fetch data from:
- Contentful
- Sanity
- WordPress Headless CMS
- Databases
- APIs
The route will automatically build the latest version of your LLMs.txt file.
Optional: Enable Caching
Next.js allows you to cache the response and refresh it automatically every few hours or days.
This helps improve performance while keeping the content updated.
Best For
- News websites
- Large blogs
- E-commerce stores
- CMS-driven websites
- Frequently updated projects
Method 3: Pages Router Projects
If your project uses the older Pages Router instead of the App Router, you can create an API route.
Step 1: Create an API File
Create:
pages/api/llms-txt.js
The API route will return the content of your LLMs.txt file.
Step 2: Add a Redirect
Update your Next.js configuration so that:
/llms.txt
points to:
/api/llms-txt
Once configured, visitors and AI tools can access your LLMs.txt file from the standard URL.
Best For
- Older Next.js websites
- Legacy projects
- Websites using the Pages Router
Which Method Should You Choose?
| Method | Best For | Difficulty |
|---|---|---|
| Static File in /public | Most websites | Very Easy |
| Dynamic App Router | CMS and frequently updated websites | Medium |
| Pages Router API Route | Older Next.js projects | Medium |
For most website owners, the static file method is the fastest and simplest solution.
Create Your LLMs.txt File Automatically
You don’t need to create the file manually.
Simply enter your website URL into the LLMs.txt Generator and the tool will automatically create a structured LLMs.txt file for your site.
The generated file can be downloaded and added to your Next.js project in just a few minutes.
Benefits
- No coding required
- Fast generation
- AI-friendly structure
- Works with any Next.js website
- Free to use
Generate your LLMs.txt file today and help AI systems better understand your website.
Latest LLMs.txt Guides & Tutorials
Browse all posts, guides, examples, and tutorials from LLMs txt Generator.