Skip to content
GEO AI
AnalyzerCLIDocumentationSpecificationContact
Documentation

Getting Started

  • Introduction
  • Quick Start
  • Choose Your Package

GEO Specification

  • Overview
  • llms.txt
  • AI Metadata
  • Crawler Rules
  • Structured Signals
  • Scoring
  • Recommendations

Packages

  • GEO AI Core
  • GEO AI Next
  • GEO AI Woo
  • GEO AI Shopify

Analyzer

  • Overview
  • Scoring
  • Recommendations

CLI

  • GEO AI CLI

Integrations

  • NestJSsoon
  • Laravelsoon

Reference

  • Configuration
  • API Reference
  • FAQ
DocsPackagesNext

GEO AI Next

Next.js integration for geo-ai-core — static file generation, middleware, and App Router route handler for llms.txt and llms-full.txt.

npm install geo-ai-next

Installation

bash
npm install geo-ai-next

Peer dependency: next >= 16. No need to also install geo-ai-core — everything is re-exported.

Static generation (recommended)

The most reliable production approach. Generates public/llms.txt and public/llms-full.txt before next build. Next.js serves them automatically — no middleware needed.

1. Create geo-ai.config.mjs

geo-ai.config.mjs
// @ts-check
/** @type {import('geo-ai-next').GenerateLlmsFilesConfig} */
export default {
  siteName: 'My Site',
  siteUrl: 'https://example.com',
  siteDescription: 'AI-optimized site description',
  provider: {
    Pages: [
      { title: 'Home', url: '/', description: 'Welcome page' },
      { title: 'About', url: '/about', description: 'About us' },
    ],
    Products: [
      {
        title: 'Widget Pro',
        url: '/products/widget-pro',
        description: 'Our flagship widget',
        price: '$29.99',
        available: true,
      },
    ],
  },
  crawlers: 'all',
};

Add the build script to package.json:

package.json
{
  "scripts": {
    "geo:generate": "geo-ai-generate",
    "build": "npm run geo:generate && next build"
  }
}

Run the build and verify:

bash
npm run build

# Both files should be present
ls public/llms.txt public/llms-full.txt

Custom config path

By default the CLI reads geo-ai.config.mjs from your project root. Pass --config ./path/to/config.mjs to use a different location.

Troubleshooting 404s on /llms.txt

  • Make sure geo-ai-generate runs before next build
  • Check that public/llms.txt exists after generation
  • Vercel and Netlify serve public/ automatically — no extra config needed
  • For custom servers, ensure static file serving is configured for the public/ directory

Middleware

Use middleware when you need dynamic content per-request — locale from cookies, A/B testing, or content that changes too frequently to regenerate at build time.

middleware.ts
import { geoAIMiddleware } from 'geo-ai-next';

export default geoAIMiddleware({
  siteName: 'My Site',
  siteUrl: 'https://example.com',
  provider: new MyProvider(),
  cache: '24h',
  cacheMaxAge: 3600,       // Cache-Control max-age in seconds
  injectLinkHeader: true,  // Adds Link header to all responses
});

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

Route handler

For App Router — serves llms content at a custom route. File type is determined by URL path or ?type=full query param.

app/llms/route.ts
import { createLlmsHandler } from 'geo-ai-next';

export const { GET } = createLlmsHandler({
  siteName: 'My Site',
  siteUrl: 'https://example.com',
  provider: new MyProvider(),
  cacheMaxAge: 3600, // optional, default 3600
});

Re-exports

All public API from geo-ai-core is re-exported — no need to install both packages:

typescript
import {
  createGeoAI,
  BotRulesEngine,
  CrawlTracker,
  SeoGenerator,
  AI_BOTS,
  type ContentProvider,
  type Resource,
  type GeoAIConfig,
} from 'geo-ai-next';

When to use each approach

ApproachWhen to use
Static generation (CLI)Production default — works on Vercel, Netlify, any static host
MiddlewareDynamic content per-request, edge locale detection, A/B testing
Route handlerCustom route path, App Router, programmatic control
PreviousGEO AI CoreNextGEO AI Woo

On this page

  • Installation
  • Static generation (recommended)
  • CLI
  • Troubleshooting 404s
  • Middleware
  • Route handler
  • Re-exports
  • When to use each approach
GEO AI

AI Search Optimization

AnalyzerCLIDocumentationSpecificationContact

© 2026 GEO AI · Open Source · GPL-2.0 License