DEV Community

cadguide.tools
cadguide.tools

Posted on Originally published at geokit.site

How to Serve a Zero-Cost, Dynamic llms.txt on Cloudflare Pages and Next.js

As AI search engines like ChatGPT Search, Perplexity, and Claude increasingly query websites for real-time citations, providing an /llms.txt endpoint has become standard practice.

However, if your website receives substantial traffic or is deployed to the edge (such as Cloudflare Pages or Vercel), you want your llms.txt endpoint to be:

  1. Dynamic & Configurable: Easily updated as new documentation or features are released.
  2. Edge-Cached & Fast: Instant response times for AI crawlers without consuming serverless invocation limits.
  3. Zero-Cost: Executing 100% within free-tier edge limits.

In this guide, we'll demonstrate how to set up an edge-optimized /llms.txt route in Next.js 15 deployed on Cloudflare Pages.


🛠️ Step 1: Create the Dynamic Route Handler

In your Next.js App Router project, create app/llms.txt/route.ts:

import { NextResponse } from "next/server";

export const runtime = "edge"; // Run on Cloudflare Edge

export async function GET() {
  const llmsContent = `# GEOKit
> Free, privacy-first Generative Engine Optimization (GEO) & AI SEO toolkit.

## Core Documentation & Tools
- [llms.txt Generator](https://geokit.site/tools/llms-txt-generator): Generate and validate compliant llms.txt files.
- [AI Robots.txt Builder](https://geokit.site/tools/ai-robots-txt-generator): Configure granular rules for GPTBot, ClaudeBot, and PerplexityBot.
- [AI Readiness Checker](https://geokit.site/tools/ai-readiness-checker): Audit page digestability for generative search engines.
- [JSON-LD Schema Builder](https://geokit.site/tools/schema-generator): Structured data tailored for AI knowledge graphs.

## Machine-Readable Assets
- [Full LLM Markdown Guide](https://geokit.site/llms-full.txt)
- [OpenAPI Specification](https://geokit.site/openapi.yaml)
`;

  return new NextResponse(llmsContent, {
    headers: {
      "Content-Type": "text/plain; charset=utf-8",
      "Cache-Control": "public, max-age=86400, s-maxage=86400, stale-while-revalidate=3600",
      "Cloudflare-CDN-Cache-Control": "max-age=86400",
    },
  });
}
Enter fullscreen mode Exit fullscreen mode

⚡ Step 2: Test & Validate Your Endpoint

Before deploying to production, verify that your markdown syntax, link targets, and heading hierarchy conform to standard LLM ingestion models.

You can use the free web utilities available on GEOKit:


🚀 Conclusion

With edge caching on Cloudflare Pages or Vercel, serving an /llms.txt file costs $0 and ensures your web app is always ready for the next wave of generative AI crawlers.

Top comments (0)