ai-visibility docs
ai-visibility (v0.3.0) is a free, MIT-licensed npm package for AI-crawler detection, robots.txt/llms.txt generation, JSON-LD schema, content readability scoring, and crawler-visit logging in Node.js and Next.js apps. This is the canonical reference — the package README is the short version.
Install
npm install ai-visibilityRequires Node.js 18+.
Next.js quickstart
Detect AI crawlers in an edge proxy (middleware.ts, or proxy.ts on Next.js 16+) using the zero-dependency, edge-safe detector:
import { NextRequest, NextResponse } from "next/server";
import { createNextMiddleware } from "ai-visibility/next";
export const proxy = createNextMiddleware({
onDetect: (bot, req) => console.log(`${bot.name} (${bot.company}) hit ${req.nextUrl.pathname}`),
});
export const config = { matcher: "/((?!_next/static|_next/image).*)" };Then generate robots.txt and llms.txt as Route Handlers — see the App Router recipe for the full working example this site itself runs.
Express quickstart
import express from "express";
import { createAIMiddleware, optimizeResponseForAI } from "ai-visibility/express";
const app = express();
app.use(createAIMiddleware({ verbose: true }));
app.use(optimizeResponseForAI({
stripJs: true, // remove <script> tags (keeps JSON-LD)
removeAds: true,
removeTracking: true,
}));createAIMiddleware and optimizeResponseForAI are Express-only — they import types from express, which is an optional peer dependency. Next.js apps should use ai-visibility/next instead, above.
Package exports
As of 0.3.0, the package ships subpath exports alongside the root barrel, so a consumer only bundles what it actually uses — this matters most for edge runtimes (Next.js Edge Middleware, Cloudflare Workers), which can't load Node-only dependencies at all. Every method on SchemaBuilder is dependency-free except fromHTML(), which lazily loads cheerio on first call — importing ai-visibility/schema never pulls it in unless fromHTML() is actually called.
| Import | Contains | Runtime deps | Edge-safe |
|---|---|---|---|
ai-visibility | Everything (barrel) | all | No |
ai-visibility/detector | AIBotDetector, HTMLOptimizer, bot registry | none | Yes |
ai-visibility/schema | SchemaBuilder | none¹ | Yes |
ai-visibility/generators | RobotsGenerator, LLMSTextGenerator | none | Yes |
ai-visibility/express | createAIMiddleware, optimizeResponseForAI, AIVisitorLogger | express (optional peer) | No |
ai-visibility/next | createNextMiddleware, detectAndOptimize | next (optional peer) | Yes |
This site itself imports ai-visibility/detector directly in its own edge proxy, and ai-visibility/schema and ai-visibility/generators in Route Handlers — see /built-with for the real, running code.