ai-visibility docs
ai-visibility (v0.8.2) is a free, MIT-licensed npm package for AI-crawler detection, robots.txt/llms.txt generation, JSON-LD schema, a six-category AI Readiness Engine, BYOK brand-visibility measurement, citation and competitor gap analysis, and a 13-command CLI — in Node.js, Next.js, Nuxt, and React Router apps, plus build-time support for Vue and React SPAs. This is the canonical reference — the package README is the short version.
📦 Node.js / Next.js? You're in the right place — these are the npm docs.
🐍 Python / Django / Flask / FastAPI? See the Python docs instead.
Available on npm and, for Python frameworks, PyPI.
Install
npm install ai-visibilityRequires Node.js 18+. No install needed to try the CLI: npx ai-visibility audit yoursite.com — see the CLI reference.
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, detectAndOptimize, bot registry, getUnverifiedBots | 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, re-exported) | next (optional peer) | Yes |
ai-visibility/engines | OpenAIAdapter, PerplexityAdapter, GeminiAdapter, AnthropicAdapter, EngineHttpError, EngineResponseError | none | Yes |
ai-visibility/prompts | PromptDiscovery | none | Yes |
ai-visibility/measure | MeasurementEngine | none | Yes |
ai-visibility/citations | CitationAnalyzer | none | Yes |
ai-visibility/competitor | CompetitorAnalyzer | none | 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.
detectAndOptimize() lived only in ai-visibility/next through 0.3.0, despite being documented as framework-agnostic — importing it outside a Next.js project crashed on a missing next/server module. 0.3.1 moved it to its real home, ai-visibility/detector, still re-exported from /next for existing imports. 0.4.0 finished the subpath cleanup: /schema, /generators, and /express now re-export the parameter types that belong to them, not just the classes/functions. See the migration guideif you're upgrading from 0.2.x or 0.3.0.
AI Readiness auditing and brand measurement
Four features shipped across v0.6.0–v0.8.2, each with its own dedicated page:
- AI Readiness Engine (v0.6.0) —
ContentAnalyzer.audit(), six weighted categories and 30 checks, behindai-visibility audit/lint. - Brand measurement (v0.7.0) — BYOK queries to OpenAI, Perplexity, Gemini, and Anthropic with repeated sampling and confidence intervals. See also engine adapters and prompt discovery.
- Citation analysis and competitor gap analysis (v0.8.0) — where AI engines learned about your brand, and evidence-backed reasons a competitor is winning.
- Full report pipeline —
npx ai-visibility reportruns all of the above in one command.