Skip to main content
Setup guide

How to add llms.txt to Next.js

Next.js makes this trivial: drop the file in /public or expose a route handler that streams plain text. Both options take under five minutes.

3
Steps
3
Prereqs
2
Gotchas

Before you start

  • A Next.js app (Pages or App Router)
  • Deploy permissions
  • An llms.txt body ready to ship
Step-by-step

Install in 3 steps

  1. 1

    Static option

    Put llms.txt in /public. Next will serve it at /llms.txt automatically with the right content-type.

  2. 2

    Dynamic option (App Router)

    Create app/llms.txt/route.ts that returns new Response(content, { headers: { 'Content-Type': 'text/plain' } }).

  3. 3

    Verify

    Run next build and curl your deployed URL. Make sure no middleware rewrites the request.

Troubleshooting

Request is rewritten or redirected

middleware.ts is intercepting /llms.txt. Add a matcher exclusion: matcher: ['/((?!llms.txt).*)'].

Pages Router doesn't pick up the file

Use pages/api/llms.ts returning the body, plus a next.config.js rewrite from /llms.txt to /api/llms.

Common gotchas

  • middleware.ts can intercept root paths — add a matcher exclusion
  • If you're on the Pages Router, use pages/api/llms.ts + a rewrite in next.config.js

Generate your llms.txt in 30 seconds

Use the free OptimAIze generator, then follow the steps above to deploy on Next.js.

Frequently asked questions

Does Next.js need both llms.txt and robots.txt?

Yes. robots.txt grants crawler permission; llms.txt curates which pages matter. Together they form the minimum AI-search setup on any Next.js site.

Will adding llms.txt slow down my site?

No. It's a tiny static text file fetched once and cached aggressively. Page-load impact is effectively zero.

How often should I update llms.txt?

Whenever your canonical content set changes — new docs section, new product line, new pricing page. A monthly review is a sensible cadence for most sites.

Can I see whether AI engines read my llms.txt?

Check your server logs for user agents like GPTBot, ClaudeBot, PerplexityBot, and Google-Extended hitting /llms.txt. Most sites see traffic within days of publishing.

Other platforms

Signal
Up to 30%
AI Visibility Lift
Improved content discoverability by LLMs.
Signal
Over 50%
Reduced Scrape Stress
Lowered server load from unapproved AI agents.
Signal
High Impact
Data Integrity
Better control over how AI models interpret content.
Signal
Emerging Standard
LLM Governance
Proactive measure for AI content management.

Integrating llms.txt in Next.js for AI Visibility

For Next.js applications, publishing an `llms.txt` file is crucial for steering how AI models interact with your content. Unlike traditional `robots.txt`, `llms.txt` provides granular directives specifically for Large Language Models, influencing generative AI responses and preventing unintended use of your intellectual property. Properly implementing this file ensures that your content is either explicitly permitted or disallowed for AI training and citation, enhancing your site's discoverability in AI-powered search (AEO) while respecting your content rights. Next.js's static asset handling makes this integration straightforward, allowing for consistent deployment across environments. This proactive step helps optimize your digital presence for the evolving AI search landscape.

Strategic Placement and Configuration for Next.js

In a Next.js project, the `llms.txt` file should reside in the `public` directory at the root of your project. This ensures it's served statically from the `/llms.txt` path, making it easily discoverable by AI agents and web crawlers looking for model-specific directives. Within the file, use `User-agent` directives to target specific LLMs (e.g., `User-agent: OpenAI-GPTbot`) and `Allow` or `Disallow` rules for paths or patterns. For instance, `Disallow: /private/*` would prevent AI models from indexing private sections. Regular updates are necessary as new AI agents emerge or your content strategy evolves, treating `llms.txt` as a dynamic asset rather than a static afterthought.

Maintaining and Monitoring Your llms.txt Directives

Maintaining an effective `llms.txt` is an ongoing process, especially within a rapidly evolving Next.js application. Changes to your site's structure, new content categories, or updated AI bot behaviors necessitate reviewing and updating this file. Utilize AI visibility scanners, like OptimAIze, to verify that your `llms.txt` directives are being correctly interpreted by various AI agents and to detect any potential conflicts or gaps. Monitoring logs for unusual AI agent activity can also provide insights into whether your directives are being respected. Proactive maintenance ensures continuous alignment with your AI content governance strategy and optimal AEO performance.

Common LLM.txt Directives for Next.js

DirectivePurposeNext.js Example
User-agentTargets specific AI models or categories.User-agent: * (for all LLMs)
AllowPermits AI models to access specified paths.Allow: /blog/*
DisallowPrevents AI models from accessing paths.Disallow: /pricing-details/
Crawl-delaySuggests delay between consecutive requests.Crawl-delay: 10
NoindexRequests AI not to index specific content.Noindex: /internal-docs/

Next.js llms.txt Deployment Checklist

  • Create `llms.txt` in the `public` directory.
  • Define `User-agent` rules for relevant AI models (e.g., OpenAI-GPTbot, Bard).
  • Specify `Allow` and `Disallow` directives for key content paths.
  • Ensure no conflicts between `llms.txt` and `robots.txt` directives.
  • Regularly review and update `llms.txt` with site changes or new AI agents.
  • Use an AI visibility scanner to validate directives and potential issues.

Implementing llms.txt in Your Next.js Project

  1. 1
    Create the File

    In your Next.js project's root directory, create a `public` folder if it doesn't exist. Inside `public`, create a file named `llms.txt`.

  2. 2
    Define Directives

    Populate `llms.txt` with `User-agent`, `Allow`, and `Disallow` rules tailored to your content strategy and desired AI interaction. Use specific bot names or `*` for all.

  3. 3
    Deploy Your Site

    Deploy your Next.js application. The `llms.txt` file will be served automatically from `yourdomain.com/llms.txt` as a static asset.

  4. 4
    Verify and Monitor

    Use a browser to confirm `llms.txt` is accessible at the correct URL. Periodically scan your site with an AI visibility tool to ensure directives are correctly interpreted by LLMs and avoid unintended access.

More questions answered

Why is llms.txt necessary if I already have robots.txt for my Next.js site?
While `robots.txt` guides traditional search engine crawlers, `llms.txt` provides specific instructions for Large Language Models. These AI models often behave differently, focusing on data ingestion for training or content summarization, making a dedicated `llms.txt` essential for granular control over how your content is used by generative AI, influencing AEO and preventing misuse.
How does llms.txt impact my Next.js site's AI search visibility (AEO)?
`llms.txt` directly influences AEO by explicitly allowing AI models to access and cite specific content, improving your chances of appearing in AI-generated answers or summaries. Conversely, disallowing sensitive or low-quality content ensures that only your most valuable information contributes to your AI footprint, enhancing content trust and relevance for AI users.
Can I use llms.txt to prevent my Next.js content from being used for AI training?
Yes, `llms.txt` is designed precisely for this. By using `Disallow` directives for specific AI `User-agent` bots or setting a general `Disallow: /` for all AI agents, you can signal your intent to prevent your content from being ingested for training purposes. While not a legal enforcement tool, it serves as a strong technical and ethical signal to AI developers regarding data usage.
What happens if I forget to update my llms.txt file after a major Next.js site redesign?
Forgetting to update `llms.txt` after a redesign can lead to outdated or incorrect directives. AI models might continue to access or ignore paths based on old rules, potentially leading to undesired content being cited or valuable new content being overlooked. This can negatively impact your AI search visibility (AEO) and data governance, making regular review crucial for maintaining effective AI content control.

Explore further

Connected guides to keep going — short reads, all internally linked.