How to add llms.txt to Gatsby
Gatsby copies /static to the site root at build time. That's where llms.txt lives. Alternatively, use a serverless function on Gatsby Cloud or Netlify.
Before you start
- ✓A Gatsby project (v3+)
- ✓Deploy host: Gatsby Cloud, Netlify, or any static host
- ✓An llms.txt body ready to drop in
Install in 3 steps
- 1
Add to /static
Place llms.txt in /static at the project root.
- 2
Or create a function
On Gatsby Cloud / Netlify, add src/api/llms.ts exporting a default handler that returns plain text.
- 3
Verify
Build, then curl the deployed URL.
Troubleshooting
Add /llms.txt to the gatsby-plugin-offline exclusion list and force a SW update.
Configure your CDN to serve text/plain without forced gzip, or rely on standard Accept-Encoding negotiation.
Common gotchas
- • Gatsby plugins (gatsby-plugin-offline) may cache the file — exclude /llms.txt from the SW
- • Make sure your CDN doesn't gzip text/plain into something AI crawlers don't accept
Generate your llms.txt in 30 seconds
Use the free OptimAIze generator, then follow the steps above to deploy on Gatsby.
Frequently asked questions
Does Gatsby 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 Gatsby 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
Integrating llms.txt into Gatsby Build Workflows
Gatsby's static site generation process requires a specific approach for deploying `llms.txt`. The most effective method involves placing the file directly in the `/static` directory of your Gatsby project. Content in this directory is copied, without processing, to the root of the public directory (`/public`) during the build process. This ensures `llms.txt` is accessible at `yourdomain.com/llms.txt`, which is crucial for AI models to discover it. For dynamic content or if your project structure dictates, you might integrate a build hook or a simple `copy` command in your `package.json` scripts to move the file after a successful build, though the `/static` directory is generally preferred for simplicity and reliability.
Crafting Effective Directives for Gatsby Content
The `llms.txt` file uses directives similar to `robots.txt`, but tailored for AI models and their data ingestion. For Gatsby sites, a common strategy involves explicitly allowing AI access to specific content types or paths, while disallowing others that might be sensitive or irrelevant for AI-driven summarization. Consider your `User-Agent` directives carefully; you might use `User-Agent: *` for general AI crawlers, or specify models like `User-Agent: ChatGPT` for fine-grained control. Directives such as `Allow: /blog/` or `Disallow: /admin/` guide AI models to focus on public-facing, value-adding content, ensuring better AEO (Answer Engine Optimization) outcomes and preventing the indexing of development or private assets.
Maintaining and Monitoring llms.txt for AEO Compliance
Regular maintenance of your `llms.txt` file is vital as your Gatsby site evolves or as AI model behaviors shift. As you add new routes, components, or content types, verify their `llms.txt` directives remain accurate. Implement a review process, perhaps coinciding with major content updates or Gatsby version bumps, to ensure continuous AEO compliance. Monitoring involves checking server logs for requests to `llms.txt` from AI-specific user agents and using AI visibility scanning tools, like OptimAIze, to confirm that your directives are being interpreted as intended. This proactive approach ensures your Gatsby content is optimally positioned for AI search and knowledge integration.
llms.txt Directives for Gatsby Sites
| Directive | Description | Gatsby Application |
|---|---|---|
| User-Agent: * | Applies rules to all AI models/crawlers. | Default for broad AI visibility control across your Gatsby site. |
| User-Agent: OpenAI-GPTbot | Targets OpenAI's specific large language model. | Fine-tune content exposure for ChatGPT, DALL-E, etc., from Gatsby. |
| Allow: /public/* | Permits AI models to access specified path patterns. | Grant access to your blog posts, articles, or product pages. |
| Disallow: /dev/* | Restricts AI model access to defined paths. | Prevent AI from indexing staging, testing, or internal documentation. |
| Crawl-delay: 10 | Requests a delay between consecutive AI crawl requests (in seconds). | Manage server load during AI indexing of large Gatsby content libraries. |
Gatsby llms.txt Deployment Checklist
- Create `llms.txt` in your Gatsby project's `/static` directory.
- Define explicit `User-Agent` directives (e.g., `*`, `ChatGPT`) for AI models.
- Use `Allow` directives for content paths intended for AI consumption (e.g., `/blog/`, `/pages/`).
- Implement `Disallow` directives for private, sensitive, or duplicate content (e.g., `/admin/`, `/temp/`).
- Build and deploy your Gatsby site, verifying `llms.txt` is accessible at `yourdomain.com/llms.txt`.
- Periodically review `llms.txt` directives alongside content updates and monitor AI visibility.
Implementing llms.txt in a Gatsby Project
- 1Create File
In your Gatsby project root, create a `/static` directory if it doesn't exist. Inside `/static`, create a new file named `llms.txt`.
- 2Add Directives
Populate `llms.txt` with appropriate `User-Agent`, `Allow`, and `Disallow` rules tailored to your content strategy. Focus on what AI should and should not process.
- 3Build & Deploy
Run `gatsby build` and deploy your site. Gatsby will automatically copy `/static/llms.txt` to the root of your `public` directory, making it available.
- 4Verify Access
After deployment, navigate to `yourdomain.com/llms.txt` in a browser to confirm it's accessible and contains the correct directives. Use AI visibility tools for deeper validation.
More questions answered
- Why do I need an llms.txt file for my Gatsby site?
- An `llms.txt` file helps you proactively manage how large language models (LLMs) and other AI systems crawl and index your Gatsby content. It's crucial for guiding AI visibility, ensuring relevant data is used for AEO, and preventing unwanted or inaccurate AI-driven summaries of your site's information. It's a key tool for modern AI search optimization.
- How is llms.txt different from robots.txt for Gatsby?
- While `robots.txt` primarily guides traditional search engine crawlers, `llms.txt` is specifically designed for AI models and their content ingestion patterns. It uses similar syntax but focuses on directives relevant to how AI extracts, summarizes, and uses information. For Gatsby, both files live at the root, serving distinct but complementary roles in site visibility management.
- Can I use dynamic content in my Gatsby llms.txt?
- The `llms.txt` file itself is typically static, residing in Gatsby's `/static` directory and copied directly. While Gatsby generates dynamic pages, the `llms.txt` file's purpose is to provide static rules. If you need highly dynamic AI access rules, you might consider server-side logic to generate the `llms.txt` content before the Gatsby build, though this adds complexity and is rarely necessary.
- What happens if I don't implement llms.txt on my Gatsby site?
- Without `llms.txt`, your Gatsby content might be ingested by AI models without specific guidance, potentially leading to less accurate AEO outcomes. Unwanted content could be summarized, or critical pages might be overlooked. Implementing `llms.txt` offers a degree of control over your AI visibility, making your content more effective in AI-powered search and generation contexts.
Explore further
Connected guides to keep going — short reads, all internally linked.