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.
Installation
npm install geo-ai-nextPeer 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
// @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:
{
"scripts": {
"geo:generate": "geo-ai-generate",
"build": "npm run geo:generate && next build"
}
}Run the build and verify:
npm run build
# Both files should be present
ls public/llms.txt public/llms-full.txtCustom config path
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-generateruns beforenext build - Check that
public/llms.txtexists 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.
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.
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:
import {
createGeoAI,
BotRulesEngine,
CrawlTracker,
SeoGenerator,
AI_BOTS,
type ContentProvider,
type Resource,
type GeoAIConfig,
} from 'geo-ai-next';When to use each approach
| Approach | When to use |
|---|---|
| Static generation (CLI) | Production default — works on Vercel, Netlify, any static host |
| Middleware | Dynamic content per-request, edge locale detection, A/B testing |
| Route handler | Custom route path, App Router, programmatic control |