@aiedx/fetchlens-next
v0.1.8
Published
AI bot detection middleware for Next.js — works on any host
Maintainers
Readme
@aiedx/fetchlens-next
AI bot detection middleware for Next.js. Detects 26 AI agents (GPTBot, ClaudeBot, PerplexityBot, and more) hitting your site in real-time. Works on any host — Vercel, AWS Amplify, Netlify, Cloudflare, self-hosted.
Why
Google Analytics, Plausible, and every other analytics tool are 100% blind to AI bot traffic. These bots don't run JavaScript, so they never appear in your dashboards. FetchLens detects them at the middleware layer.
Install
npm install @aiedx/fetchlens-nextSetup
Create middleware.ts in your project root:
import { withFetchLens } from '@aiedx/fetchlens-next'
export const middleware = withFetchLens({
siteId: 'yourdomain.com',
apiEndpoint: 'https://fetchlens.ai',
siteTag: 'fl_pub_your_key',
})
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico|api/).*)'],
}Get your Site Tag by scanning your domain at fetchlens.ai.
What it detects
| Provider | Bots | |----------|------| | OpenAI | GPTBot, ChatGPT-User, OAI-SearchBot | | Anthropic | ClaudeBot, Claude-SearchBot, Claude-User, Claude-Code, anthropic-ai | | Perplexity | PerplexityBot, Perplexity-User | | Google | Google-Extended, Google-CloudVertexBot | | Apple | Applebot-Extended | | Meta | meta-externalagent, meta-externalfetcher, FacebookBot | | Others | DuckAssistBot, MistralAI-User, Bytespider, cohere-ai, Amazonbot, PetalBot, Diffbot, PhindBot, YouBot, CCBot |
Features
- Zero-latency — detection runs asynchronously via
waitUntil, no impact on page load - Vulnerability scan blocking — automatically blocks probes for
.php,/wp-admin,.env, etc. with a 403 (configurable) - Server-side only — no client bundle impact, works with all rendering modes (SSR, SSG, ISR)
- 26 AI bot signatures — covers all major AI crawlers and training bots
Configuration
withFetchLens({
siteId: 'yourdomain.com', // Required: your domain
apiEndpoint: 'https://fetchlens.ai', // Required: FetchLens API URL
siteTag: 'fl_pub_xxx', // Your Site Tag (from install guide)
blockVulnScans: true, // Block vulnerability probes (default: true)
})How it works
- Every request passes through Next.js middleware
- FetchLens extracts the user agent, headers, and request metadata
- The payload is sent asynchronously to the FetchLens API (zero latency impact)
- The API identifies the bot using 26 known signatures + heuristic detection
- Results appear on your FetchLens dashboard
Requirements
- Next.js 14+
- Node.js 18+
License
Proprietary. Copyright (c) 2026 AIEDX Private Limited.
