Bot protection reference
Arcjet bot detection lets you manage traffic by automated clients and bots.
Configuration
Section titled “Configuration”Bot detection is configured by allowing or denying a subset of bots. You must
pass exactly one of allow or deny. The lists are mutually exclusive. With
allow, Arcjet denies any detected bot that the list does not name. With
deny, Arcjet allows any detected bot that the list does not name.
An empty allow list is valid and blocks every detected bot. In Python,
detect_bot and the BotDetection dataclass raise ValueError if you pass
neither list or both lists.
You can use only one of the following configuration definitions:
type BotOptionsAllow = { mode?: "LIVE" | "DRY_RUN"; allow: Array<ArcjetWellKnownBot | ArcjetBotCategory>;};type BotOptionsDeny = { mode?: "LIVE" | "DRY_RUN"; deny: Array<ArcjetWellKnownBot | ArcjetBotCategory>;};The arcjet client is configured with one or more detectBot rules which take
one or many BotOptions.
# Signature for arcjet.detect_bot# Pass exactly one of `allow` or `deny`. Passing neither or both raises# ValueError. An empty allow=[] blocks every detected bot.def detect_bot( *, # Required. Mode.LIVE blocks requests; Mode.DRY_RUN logs only. mode: Mode, # Bots to permit. All other detected bots are denied. allow: Sequence[str | BotCategory] | None = None, # Bots to block. All other detected bots are allowed. deny: Sequence[str | BotCategory] | None = None,) -> BotDetection: ...The arcjet (or arcjet_sync) client is configured with one or more
detect_bot rules. Pass BotCategory.<NAME> enum values for categories and
string identifiers like "CURL" for specific bots.
Declaration order does not control which LIVE deny you see. The JS, Go, and
Python SDKs sort local Protect rules in the same order: Sensitive Info, Filter,
Shield, rate limiting, Bot, Email, then Prompt Injection. Rules with the same
priority keep their declaration order. For details about examining the results,
see Decision. For the Python priority table, see
Multiple rules in the Python SDK reference.
Allow specific bots
Section titled “Allow specific bots”Most applications want to block almost all bots. However, it is common to allow some bots to access your system, such as bots for search indexing or API access from the command line.
When allowing specific bots we recommend that you also check the verification status after an allow decision is returned to ensure that the bots are who they say they are.
Configure this behavior with an allow list drawn from the full list of
bots, from bot categories, or from both.
import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // Google has multiple crawlers, each with a different user-agent, so we // allow the entire Google category "CATEGORY:GOOGLE", "CURL", // allows the default user-agent of the `curl` tool "DISCORD_CRAWLER", // allows Discordbot ], }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
if (decision.isDenied()) { // Bots not in the allow list will be blocked if (decision.reason.isBot()) { return res.status(403).json({ error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); } else { return res.status(403).json({ error: "Forbidden", }); } }
// Paid Arcjet accounts include additional verification checks using IP data. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return res.status(403).json({ error: "You are pretending to be a good bot!", }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // Google has multiple crawlers, each with a different user-agent, so we // allow the entire Google category "CATEGORY:GOOGLE", "CURL", // allows the default user-agent of the `curl` tool "DISCORD_CRAWLER", // allows Discordbot ], }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
if (decision.isDenied()) { // Bots not in the allow list will be blocked if (decision.reason.isBot()) { return res.status(403).json({ error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); } else { return res.status(403).json({ error: "Forbidden", }); } }
// Paid Arcjet accounts include additional verification checks using IP data. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return res.status(403).json({ error: "You are pretending to be a good bot!", }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // Google has multiple crawlers, each with a different user-agent, so we // allow the entire Google category "CATEGORY:GOOGLE", "CURL", // allows the default user-agent of the `curl` tool "DISCORD_CRAWLER", // allows Discordbot ], }), ],});
export async function POST(req: Request) { const decision = await aj.protect(req);
if (decision.isDenied()) { // Bots not in the allow list will be blocked if (decision.reason.isBot()) { return NextResponse.json( { error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }, { status: 403 }, ); } else { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } }
// Paid Arcjet accounts include additional verification checks using IP data. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return NextResponse.json( { error: "You are pretending to be a good bot!" }, { status: 403 }, ); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // Google has multiple crawlers, each with a different user-agent, so we // allow the entire Google category "CATEGORY:GOOGLE", "CURL", // allows the default user-agent of the `curl` tool "DISCORD_CRAWLER", // allows Discordbot ], }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req);
if (decision.isDenied()) { // Bots not in the allow list will be blocked if (decision.reason.isBot()) { return res.status(403).json({ error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); } else { return res.status(403).json({ error: "Forbidden", }); } }
// Paid Arcjet accounts include additional verification checks using IP data. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return res.status(403).json({ error: "You are pretending to be a good bot!", }); }
res.status(200).json({ name: "Hello world" });}Deny specific bots
Section titled “Deny specific bots”Some applications may only want to block a small subset of bots, while allowing the majority continued access. This may be due to many reasons, such as misconfigured or high-traffic bots.
Configure this behavior with a deny list drawn from the full list of
bots, from bot categories, or from both.
import arcjet, { detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to deny from // https://arcjet.com/bot-list - all other detected bots will be allowed deny: [ "CATEGORY:AI", // denies all detected AI and LLM scrapers "CURL", // denies the default user-agent of the `curl` tool ], }), ],});
export async function POST(req: Request) { const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) { return NextResponse.json( { error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }, { status: 403 }, ); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to deny from // https://arcjet.com/bot-list - all other detected bots will be allowed deny: [ "CATEGORY:AI", // denies all detected AI and LLM scrapers "CURL", // denies the default user-agent of the `curl` tool ], }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req); console.log("Decision", decision);
if (decision.isDenied() && decision.reason.isBot()) { return res.status(403).json({ error: "Forbidden", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to deny from // https://arcjet.com/bot-list - all other detected bots will be allowed deny: [ "CATEGORY:AI", // denies all detected AI and LLM scrapers "CURL", // denies the default user-agent of the `curl` tool ], }), ],});
export async function POST(req) { const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) { return NextResponse.json( { error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }, { status: 403 }, ); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to deny from // https://arcjet.com/bot-list - all other detected bots will be allowed deny: [ "CATEGORY:AI", // denies all detected AI and LLM scrapers "CURL", // denies the default user-agent of the `curl` tool ], }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req); console.log("Decision", decision);
if (decision.isDenied() && decision.reason.isBot()) { return res.status(403).json({ error: "Forbidden", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); }
res.status(200).json({ name: "Hello world" });}Per route versus middleware
Bot protection rules can be configured in two ways:
- Route handlers: The rule is defined in the route handler (previously known as an API route) itself. This lets you configure the rule alongside the code it is protecting which is useful if you want to use the decision to add context to your own code. However, it means rules are not automatically applied to every request.
- Middleware/Proxy: The rule is defined in the middleware (renamed to proxy in Next.js 16). This lets you configure rules in a single place or apply them globally to all routes, but it means the rules are not located alongside the code they are protecting and can miss route specific context .
Per route
This configures bot protection on a single route.
import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) { return res.status(403).json({ error: "You are a bot!" }); }
// Paid Arcjet accounts include additional verification checks using IP data. // Verification isn't always possible, so we recommend checking the results // separately. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return res.status(403).json({ error: "You are a bot!" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) { return res.status(403).json({ error: "You are a bot!" }); }
// Paid Arcjet accounts include additional verification checks using IP data. // Verification isn't always possible, so we recommend checking the results // separately. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return res.status(403).json({ error: "You are a bot!" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function GET(req: Request) { const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) { return NextResponse.json( { error: "You are a bot!", }, { status: 403 }, ); }
// Paid Arcjet accounts include additional verification checks using IP data. // Verification isn't always possible, so we recommend checking the results // separately. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return NextResponse.json( { error: "You are a bot!", }, { status: 403 }, ); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";import { isSpoofedBot } from "@arcjet/inspect";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function GET(req) { const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) { return NextResponse.json( { error: "You are a bot!", }, { status: 403 }, ); }
// Paid Arcjet accounts include additional verification checks using IP data. // Verification isn't always possible, so we recommend checking the results // separately. // https://docs.arcjet.com/bot-protection/reference#bot-verification if (decision.results.some(isSpoofedBot)) { return NextResponse.json( { error: "You are a bot!", }, { status: 403 }, ); }
return NextResponse.json({ message: "Hello world", });}Middleware
This runs on every request to your Next.js app, except for static assets
(configured in the matcher - see the Next.js
docs
for details).
Create a file called proxy.ts (Next.js 16) or middleware.ts (Next.js 15)
in your project root (at the same level as pages or app or inside src):
import arcjet, { createMiddleware, detectBot } from "@arcjet/next";export const config = { // matcher tells Next.js which routes to run the middleware on. // This runs the middleware on all routes except for static assets. matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],};const aj = arcjet({ key: process.env.ARCJET_KEY!, // Get your site key from https://console.arcjet.com rules: [ detectBot({ mode: "LIVE", // will block requests. Use "DRY_RUN" to log only // Block all bots except the following allow: [ "CATEGORY:SEARCH_ENGINE", // Google, Bing, etc // Uncomment to allow these other common bot categories // See the full list at https://arcjet.com/bot-list //"CATEGORY:MONITOR", // Uptime monitoring services //"CATEGORY:PREVIEW", // Link previews such as Slack, Discord ], }), ],});// Pass any existing middleware with the optional existingMiddleware propexport default createMiddleware(aj);You can also customize the response depending on the decision. In this case we return a 403 Forbidden response only if we detect a hosting provider IP address for the bot detection rule result:
import arcjet, { detectBot } from "@arcjet/next";import { NextRequest, NextResponse } from "next/server";
export const config = { // matcher tells Next.js which routes to run the middleware on. // This runs the middleware on all routes except for static assets. matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],};const aj = arcjet({ key: process.env.ARCJET_KEY!, // Get your site key from https://console.arcjet.com rules: [ detectBot({ mode: "LIVE", // will block requests. Use "DRY_RUN" to log only allow: [], // "allow none" will block all detected bots }), ],});
export default async function middleware(request: NextRequest) { const decision = await aj.protect(request);
if ( // If the decision is deny because the request is from a bot and the bot IP // address is from a known hosting provider, then block the request decision.isDenied() && decision.reason.isBot() && decision.ip.isHosting() ) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } else { return NextResponse.next(); }}Create a file called proxy.js in your project root (at the same level as
pages or app or inside src):
import arcjet, { createMiddleware, detectBot } from "@arcjet/next";export const config = { // matcher tells Next.js which routes to run the middleware on. // This runs the middleware on all routes except for static assets. matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],};const aj = arcjet({ key: process.env.ARCJET_KEY, // Get your site key from https://console.arcjet.com rules: [ detectBot({ mode: "LIVE", // will block requests. Use "DRY_RUN" to log only // Block all bots except the following allow: [ "CATEGORY:SEARCH_ENGINE", // Google, Bing, etc // Uncomment to allow these other common bot categories // See the full list at https://arcjet.com/bot-list //"CATEGORY:MONITOR", // Uptime monitoring services //"CATEGORY:PREVIEW", // Link previews such as Slack, Discord ], }), ],});// Pass any existing middleware with the optional existingMiddleware propexport default createMiddleware(aj);You can also customize the response depending on the decision. In this case we return a 403 Forbidden response only if we detect a hosting provider IP address for the bot detection rule result:
import arcjet, { detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
export const config = { // matcher tells Next.js which routes to run the middleware on. // This runs the middleware on all routes except for static assets. matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],};const aj = arcjet({ key: process.env.ARCJET_KEY, // Get your site key from https://console.arcjet.com rules: [ detectBot({ mode: "LIVE", // will block requests. Use "DRY_RUN" to log only allow: [], // "allow none" will block all detected bots }), ],});
export default async function middleware(request) { const decision = await aj.protect(request);
if ( // If the decision is deny because the request is from a bot and the bot IP // address is from a known hosting provider, then block the request decision.isDenied() && decision.reason.isBot() && decision.ip.isHosting() ) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } else { return NextResponse.next(); }}Avoid double protection
If you use Arcjet in middleware/proxy and individual routes, you need to be careful that Arcjet is not running multiple times per request. This can be avoided by excluding the API route from the middleware matcher.
For example, if you already have a bot detection rule defined in the API route
at /api/hello, you can exclude it from the middleware by specifying a matcher
in /proxy.ts:
import arcjet, { createMiddleware, detectBot } from "@arcjet/next";export const config = { // The matcher prevents the middleware executing on static assets and the // /api/hello API route because you already installed Arcjet directly matcher: ["/((?!_next/static|_next/image|favicon.ico|api/hello).*)"],};const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});// Pass any existing middleware with the optional existingMiddleware propexport default createMiddleware(aj);Pages and server actions
Arcjet can be used inside Next.js middleware, API routes, pages, server components, and server actions. Client components cannot be protected because they run on the client only.
See the Next.js SDK reference for examples of pages and page components and server actions.
Decision
Section titled “Decision”The quick start example denies requests that match the bot detection rules, immediately returning a response to the client.
Arcjet provides a single protect function that is used to execute your
protection rules. This requires a request argument which is the request
context as passed to the request handler.
This function returns a Promise that resolves to an
ArcjetDecision object. This contains the following properties:
id(string) – The unique ID for the request. This can be used to look up the request in the Arcjet dashboard. It is prefixed withreq_for decisions involving the Arcjet cloud API. For decisions taken locally, the prefix islreq_.conclusion(ArcjetConclusion) – The final conclusion based on evaluating each of the configured rules. If you wish to accept Arcjet’s recommended action based on the configured rules then you can use this property.reason(ArcjetReason) – An object containing more detailed information about the conclusion.results(ArcjetRuleResult[]) – An array ofArcjetRuleResultobjects containing the results of each rule that was executed.ip(ArcjetIpDetails) – An object containing Arcjet’s analysis of the client IP address. For more information, see the SDK reference.
To check whether a bot protection rule returned a deny conclusion, use
decision.isDenied() and decision.reason.isBot() (JS) /
decision.is_denied() and decision.reason_v2.type == "BOT" (Python).
You can iterate through the results and check whether a bot protection rule was applied:
for (const result of decision.results) { console.log("Rule Result", result);}for result in decision.results: print("Rule Result", result)This example logs the results of each rule execution.
import arcjet, { fixedWindow, detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ fixedWindow({ mode: "LIVE", window: "1h", max: 60, }), detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function POST(req: Request) { const decision = await aj.protect(req);
for (const result of decision.results) { console.log("Rule Result", result);
if (result.reason.isRateLimit()) { console.log("Rate limit rule", result); }
if (result.reason.isBot()) { console.log("Bot protection rule", result); } }
if (decision.isDenied()) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { fixedWindow, detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ fixedWindow({ mode: "LIVE", window: "1h", max: 60, }), detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function POST(req) { const decision = await aj.protect(req);
for (const result of decision.results) { console.log("Rule Result", result);
if (result.reason.isRateLimit()) { console.log("Rate limit rule", result); }
if (result.reason.isBot()) { console.log("Bot protection rule", result); } }
if (decision.isDenied()) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { fixedWindow, detectBot } from "@arcjet/next";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ fixedWindow({ mode: "LIVE", window: "1h", max: 60, }), detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req); console.log("Decision", decision);
for (const result of decision.results) { console.log("Rule Result", result);
if (result.reason.isRateLimit()) { console.log("Rate limit rule", result); }
if (result.reason.isBot()) { console.log("Bot protection rule", result); } }
if (decision.isDenied()) { return res .status(403) .json({ error: "Forbidden", reason: decision.reason }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { fixedWindow, detectBot } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ fixedWindow({ mode: "LIVE", window: "1h", max: 60, }), detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req); console.log("Decision", decision);
for (const result of decision.results) { console.log("Rule Result", result);
if (result.reason.isRateLimit()) { console.log("Rate limit rule", result); }
if (result.reason.isBot()) { console.log("Bot protection rule", result); } }
if (decision.isDenied()) { return res .status(403) .json({ error: "Forbidden", reason: decision.reason }); }
res.status(200).json({ name: "Hello world" });}Identified bots
Section titled “Identified bots”The decision also contains all of the identified bots and matched categories detected from the request. A request
may be identified as zero, one, or more bots/categories-all of which are
available on the decision.allowed and decision.denied properties.
import arcjet, { detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function POST(req: Request) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isBot()) { console.log("detected + allowed bots", reason.allowed); console.log("detected + denied bots", reason.denied);
// Arcjet Pro plan verifies the authenticity of common bots using IP data // https://docs.arcjet.com/bot-protection/reference#bot-verification if (reason.isSpoofed()) { console.log("spoofed bot", reason.spoofed); }
if (reason.isVerified()) { console.log("verified bot", reason.verified); } } }
if (decision.isDenied()) { return NextResponse.json({ error: "You are a bot!" }, { status: 403 }); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isBot()) { console.log("detected + allowed bots", reason.allowed); console.log("detected + denied bots", reason.denied);
// Arcjet Pro plan verifies the authenticity of common bots using IP data // https://docs.arcjet.com/bot-protection/reference#bot-verification if (reason.isSpoofed()) { console.log("spoofed bot", reason.spoofed); }
if (reason.isVerified()) { console.log("verified bot", reason.verified); } } }
if (decision.isDenied()) { return res.status(403).json({ error: "Forbidden" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isBot()) { console.log("detected + allowed bots", reason.allowed); console.log("detected + denied bots", reason.denied);
// Arcjet Pro plan verifies the authenticity of common bots using IP data // https://docs.arcjet.com/bot-protection/reference#bot-verification if (reason.isSpoofed()) { console.log("spoofed bot", reason.spoofed); }
if (reason.isVerified()) { console.log("verified bot", reason.verified); } } }
if (decision.isDenied()) { return res.status(403).json({ error: "Forbidden" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function POST(req) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isBot()) { console.log("detected + allowed bots", reason.allowed); console.log("detected + denied bots", reason.denied);
// Arcjet Pro plan verifies the authenticity of common bots using IP data // https://docs.arcjet.com/bot-protection/reference#bot-verification if (reason.isSpoofed()) { console.log("spoofed bot", reason.spoofed); }
if (reason.isVerified()) { console.log("verified bot", reason.verified); } } }
if (decision.isDenied()) { return NextResponse.json({ error: "You are a bot!" }, { status: 403 }); }
return NextResponse.json({ message: "Hello world", });}Error handling
Section titled “Error handling”Arcjet is designed to fail open so that a service issue or misconfiguration does not block all requests. The SDK also times out and fails open after 2000 ms by default. However, in most cases, the response time is less than 20 ms to 30 ms.
If there is an error condition when processing the rule, Arcjet returns an
ERROR result for that rule and you can check the message property on the
rule’s error result for more information.
If all other rules that were run returned an ALLOW result, then the final
Arcjet conclusion is ERROR.
import arcjet, { detectBot } from "@arcjet/next";import { isMissingUserAgent } from "@arcjet/inspect";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isError()) { // Fail open by logging the error and continuing console.warn("Arcjet error", reason.message); // You could also fail closed here for very sensitive routes //return res.status(503).json({ error: "Service unavailable" }); } }
if (decision.isDenied()) { return res.status(403).json({ error: "You are a bot!", }); }
if (decision.results.some(isMissingUserAgent)) { // Requests without User-Agent headers could not be identified as any // particular bot and might be marked as an errored result. Most legitimate // clients send this header, so we recommend blocking requests without it. // See https://docs.arcjet.com/bot-protection/reference#user-agent-header console.warn("User-Agent header is missing");
return res.status(400).json({ error: "Bad request" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { isMissingUserAgent } from "@arcjet/inspect";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isError()) { // Fail open by logging the error and continuing console.warn("Arcjet error", reason.message); // You could also fail closed here for very sensitive routes //return res.status(503).json({ error: "Service unavailable" }); } }
if (decision.isDenied()) { return res.status(403).json({ error: "You are a bot!", }); }
if (decision.results.some(isMissingUserAgent)) { // Requests without User-Agent headers might not be identified as any // particular bot and could be marked as an errored result. Most legitimate // clients send this header, so we recommend blocking requests without it. // See https://docs.arcjet.com/bot-protection/reference#user-agent-header console.warn("User-Agent header is missing");
return res.status(400).json({ error: "Bad request" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { isMissingUserAgent } from "@arcjet/inspect";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function GET(req: Request) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isError()) { // Fail open by logging the error and continuing console.warn("Arcjet error", reason.message); // You could also fail closed here for very sensitive routes // return NextResponse.json( // { // error: "Service unavailable", // }, // { status: 503 }, // ); } }
if (decision.isDenied()) { return NextResponse.json( { error: "You are a bot!", }, { status: 403, }, ); }
if (decision.results.some(isMissingUserAgent)) { // Requests without User-Agent headers might not be identified as any // particular bot and could be marked as an errored result. Most legitimate // clients send this header, so we recommend blocking requests without it. // See https://docs.arcjet.com/bot-protection/reference#user-agent-header console.warn("User-Agent header is missing");
return NextResponse.json( { error: "Bad request", }, { status: 400 }, ); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";import { isMissingUserAgent } from "@arcjet/inspect";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function GET(req) { const decision = await aj.protect(req);
for (const { reason } of decision.results) { if (reason.isError()) { // Fail open by logging the error and continuing console.warn("Arcjet error", reason.message); // You could also fail closed here for very sensitive routes // return NextResponse.json( // { // error: "Service unavailable", // }, // { status: 503 }, // ); } }
if (decision.isDenied()) { return NextResponse.json( { error: "You are a bot!", }, { status: 403 }, ); }
if (decision.results.some(isMissingUserAgent)) { // Requests without User-Agent headers might not be identified as any // particular bot and could be marked as an errored result. Most legitimate // clients send this header, so we recommend blocking requests without it. // See https://docs.arcjet.com/bot-protection/reference#user-agent-header console.warn("User-Agent header is missing");
return NextResponse.json( { error: "Bad request", }, { status: 400 }, ); }
return NextResponse.json({ message: "Hello world", });}Filter categories
Section titled “Filter categories”All categories are also provided as enumerations, which allows for programmatic
access. For example, you may want to allow most of CATEGORY:GOOGLE except
their “advertising quality” bot.
import arcjet, { botCategories, detectBot } from "@arcjet/next";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // filter a category to remove individual bots from our provided lists ...botCategories["CATEGORY:GOOGLE"].filter( (bot) => bot !== "GOOGLE_ADSBOT" && bot !== "GOOGLE_ADSBOT_MOBILE", ), ], }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
if (decision.reason.isBot()) { if (decision.isDenied()) { return res.status(403).json({ error: "Forbidden", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); } }
res.status(200).json({ name: "Hello world" });}import arcjet, { botCategories, detectBot } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // filter a category to remove individual bots from our provided lists ...botCategories["CATEGORY:GOOGLE"].filter( (bot) => bot !== "GOOGLE_ADSBOT" && bot !== "GOOGLE_ADSBOT_MOBILE", ), ], }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req);
if (decision.reason.isBot()) { if (decision.isDenied()) { return res.status(403).json({ error: "Forbidden", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }); } }
res.status(200).json({ name: "Hello world" });}import arcjet, { botCategories, detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // filter a category to remove individual bots from our provided lists ...botCategories["CATEGORY:GOOGLE"].filter( (bot) => bot !== "GOOGLE_ADSBOT" && bot !== "GOOGLE_ADSBOT_MOBILE", ), ], }), ],});
export async function POST(req: Request) { const decision = await aj.protect(req);
if (decision.reason.isBot()) { if (decision.isDenied()) { return NextResponse.json( { error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }, { status: 403 }, ); } }
return NextResponse.json({ message: "Hello world", });}import arcjet, { botCategories, detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", // configured with a list of bots to allow from // https://arcjet.com/bot-list - all other detected bots will be blocked allow: [ // filter a category to remove individual bots from our provided lists ...botCategories["CATEGORY:GOOGLE"].filter( (bot) => bot !== "GOOGLE_ADSBOT" && bot !== "GOOGLE_ADSBOT_MOBILE", ), ], }), ],});
export async function POST(req) { const decision = await aj.protect(req);
if (decision.isDenied()) { if (decision.reason.isBot()) { return NextResponse.json( { error: "You are a bot!", // Useful for debugging, but don't return these to the client in // production denied: decision.reason.denied, }, { status: 403 }, ); } return NextResponse.json( { error: "Forbidden", }, { status: 403 }, ); }
return NextResponse.json({ message: "Hello world", });}Bot verification
Section titled “Bot verification”Requests analyzed by Arcjet include
automatic bot verification. For allow rules, Arcjet verifies the authenticity
of detected bots by checking IP data and performing reverse DNS lookups.
This helps protect against spoofed bots where clients pretend to be someone else.
Example: Allowing verified bots
Section titled “Example: Allowing verified bots”Well-behaved bots, such as search engine indexers, are often desirable traffic. The companies that operate these bots make them verifiable so application developers can choose to avoid additional signals about the request.
For example, when a request claims to be GoogleBot, Arcjet checks whether the IP truly belongs to Google. You can check the verification status in your code and take actions based on the results, such as allowing all verified bots.
import { isVerifiedBot } from "@arcjet/inspect";
// ...const aj = arcjet({ // ... rules: [ detectBot({ mode: "LIVE", allow: ["CATEGORY:SEARCH_ENGINE"], }), ],});
// ...const decision = await aj.protect(req);// ...
// Ignore other signals for verified search engine botsif (decision.results.some(isVerifiedBot)) { return new Response("Hello Bot!");}
// Leverage all Arcjet signalsif (decision.isDenied()) { return new Response(null, { status: 403 });}from arcjet import Mode, arcjet, detect_bot, is_verified_bot
# ...aj = arcjet( key=os.environ["ARCJET_KEY"], rules=[ detect_bot(mode=Mode.LIVE, allow=["CATEGORY:SEARCH_ENGINE"]), ],)
# ...decision = await aj.protect(request)# ...
# Ignore other signals for verified search engine botsif any(is_verified_bot(r) for r in decision.results): return JSONResponse({"message": "Hello Bot!"})
# Leverage all Arcjet signalsif decision.is_denied(): return JSONResponse(None, status_code=403)Check for spoofed bots
Section titled “Check for spoofed bots”This checks whether the bot is spoofed. You would usually return a 403 or similar response to block the request.
for (const { reason } of decision.results) { if (reason.isBot() && reason.isSpoofed()) { console.log("Detected spoofed bot", reason.spoofed); // Return a 403 or similar response }}from arcjet import is_spoofed_bot
# Use the is_spoofed_bot() helper exported by arcjet:if any(is_spoofed_bot(r) for r in decision.results): print("Detected spoofed bot") # Return a 403 or similar response
# Or inspect each rule result directly:for result in decision.results: if result.reason_v2.type == "BOT" and result.reason_v2.spoofed: print("Detected spoofed bot") # Return a 403 or similar responseCheck bot verification
Section titled “Check bot verification”This checks whether the bot is verified.
for (const { reason } of decision.results) { if (reason.isBot() && reason.isVerified()) { console.log("Verified bot", reason.verified); // Allow the request }}from arcjet import is_verified_bot
# Use the is_verified_bot() helper exported by arcjet:if any(is_verified_bot(r) for r in decision.results): print("Verified bot") # Allow the request
# Or inspect each rule result directly:for result in decision.results: if result.reason_v2.type == "BOT" and result.reason_v2.verified: print("Verified bot") # Allow the requestUser-Agent header
Section titled “User-Agent header”Requests without User-Agent headers cannot be identified as any particular
bot and are marked as an errored result.
Most legitimate clients send it because HTTP/1.1 (RFC 7231) says it should be sent. You can choose to block such requests with Arcjet Filters.
filter({ // This will deny any traffic that has no user agent: deny: ['len(http.request.headers["user-agent"]) eq 0'], // Block requests with `LIVE`, use `DRY_RUN` to log only. mode: "LIVE",}),filter_request( # This will deny any traffic that has no user agent: deny=['len(http.request.headers["user-agent"]) eq 0'], # Block requests with `LIVE`, use `Mode.DRY_RUN` to log only. mode=Mode.LIVE,)An alternative approach is to check the rule results after the decision is made:
Use the isMissingUserAgent helper from
@arcjet/inspect:
import { isMissingUserAgent } from "@arcjet/inspect";
if (decision.results.some(isMissingUserAgent)) { log.warn( { error: decision.reason.message }, "request missing required user-agent header", ); // You could return a 400 Bad request error here // Next.js example: // return NextResponse.json({ error: "Bad request" }, { status: 400 }); // Node.js example: // res.writeHead(400, { "Content-Type": "application/json" }); // res.end(JSON.stringify({ error: "Bad request" }));}Use the is_missing_user_agent helper from arcjet:
from arcjet import is_missing_user_agent
if any(is_missing_user_agent(r) for r in decision.results): logger.warning("request missing required user-agent header") # You could return a 400 Bad request error here return JSONResponse({"error": "Bad request"}, status_code=400)Testing
Section titled “Testing”Arcjet runs the same in any environment, including locally and in CI. You can
use the mode set to DRY_RUN to log the results of rule execution without
blocking any requests.
We have an example test framework you can use to automatically test your rules. Arcjet can also be triggered based using a sample of your traffic.
For details, see the Testing section of the docs.
Examples
Protect a page
You can protect a Next.js page from bots by calling the Arcjet SDK from within the page loader:
Protecting an app router page within the handler itself is not currently supported, but you can set up a matcher on the middleware (renamed to proxy in Next.js 16) instead:
import arcjet, { createMiddleware, detectBot } from "@arcjet/next";export const config = { // The matcher runs just on the /hello pages route matcher: ["/hello"],};const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});// Pass any existing middleware with the optional existingMiddleware propexport default createMiddleware(aj);Protecting an app router page within the handler itself is not currently supported, but you can set up a matcher on the middleware (renamed to proxy in Next.js 16) instead:
import arcjet, { createMiddleware, detectBot } from "@arcjet/next";export const config = { // The matcher runs just on the /hello pages route matcher: ["/hello"],};const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});// Pass any existing middleware with the optional existingMiddleware propexport default createMiddleware(aj);import arcjet, { detectBot } from "@arcjet/next";import Error from "next/error";import Head from "next/head";import React from "react";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "DRY_RUN", allow: [], // "allow none" will block all detected bots }), ],});
// getServerSideProps is called on the server before rendering the pageexport const getServerSideProps = async (context) => { const decision = await aj.protect(context.req); console.log("decision", decision);
if (decision.isDenied()) { return { props: { pageProps: { errorCode: 403, errorText: "Access denied" } }, }; }
return { props: { pageProps: { errorCode: false, errorText: "" } } };};
export default function Page({ pageProps }) { // If there is an error, render the Next.js error page if (pageProps.errorCode) { return ( <Error statusCode={pageProps.errorCode} title={pageProps.errorText} /> ); } return ( <> <Head> <title>Page</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> </Head> <main> <div> <h2>Hello</h2> </div> </main> </> );}import arcjet, { detectBot } from "@arcjet/next";import type { GetServerSideProps, InferGetServerSidePropsType } from "next";import Error from "next/error";import Head from "next/head";import React from "react";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "DRY_RUN", allow: [], // "allow none" will block all detected bots }), ],});
type pageProps = { errorCode: number | false; errorText: string;};
// getServerSideProps is called on the server before rendering the pageexport const getServerSideProps = (async (context) => { const decision = await aj.protect(context.req); console.log("decision", decision);
if (decision.isDenied()) { return { props: { pageProps: { errorCode: 403, errorText: "Access denied" } }, }; }
return { props: { pageProps: { errorCode: false, errorText: "" } } };}) satisfies GetServerSideProps<{ pageProps: pageProps;}>;
export default function Page({ pageProps,}: InferGetServerSidePropsType<typeof getServerSideProps>) { // If there is an error, render the Next.js error page if (pageProps.errorCode) { return ( <Error statusCode={pageProps.errorCode} title={pageProps.errorText} /> ); } return ( <> <Head> <title>Page</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> </Head> <main> <div> <h2>Hello</h2> </div> </main> </> );}Wrap existing handler
All the examples on this page show how you can inspect the decision to control
what to do next. However, if you just wish to send a generic 403 Forbidden
response you can delegate this to Arcjet by wrapping your handler withArcjet.
For both the Node or Edge runtime:
import arcjet, { detectBot, withArcjet } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export const GET = withArcjet(aj, async (req: Request) => { return NextResponse.json({ message: "Hello world", });});For both the Node or Edge runtime:
import arcjet, { detectBot, withArcjet } from "@arcjet/next";import { NextResponse } from "next/server";
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export const GET = withArcjet(aj, async (req) => { return NextResponse.json({ message: "Hello world", });});For the Node (default) runtime:
import arcjet, { detectBot, withArcjet } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default withArcjet( aj, async (req: NextApiRequest, res: NextApiResponse) => { res.status(200).json({ name: "Hello world" }); },);For the Edge runtime:
import arcjet, { detectBot, withArcjet } from "@arcjet/next";import { NextRequest, NextResponse } from "next/server";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default withArcjet(aj, async (req: NextRequest) => { return NextResponse.json({ message: "Hello world", });});For the Node (default) runtime:
import arcjet, { detectBot, withArcjet } from "@arcjet/next";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default withArcjet(aj, async (req, res) => { res.status(200).json({ name: "Hello world" });});For the Edge runtime:
import arcjet, { detectBot, withArcjet } from "@arcjet/next";import { NextResponse } from "next/server";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default withArcjet(aj, async (req) => { return NextResponse.json({ message: "Hello world", });});Edge Functions
Arcjet works in Edge Functions and with the Edge Runtime.
import arcjet, { detectBot } from "@arcjet/next";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler(req, res) { const decision = await aj.protect(req);
if (decision.isDenied()) { return res.status(403).json({ error: "You are a bot!" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import type { NextApiRequest, NextApiResponse } from "next";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler( req: NextApiRequest, res: NextApiResponse,) { const decision = await aj.protect(req);
if (decision.isDenied()) { return res.status(403).json({ error: "You are a bot!" }); }
res.status(200).json({ name: "Hello world" });}import arcjet, { detectBot } from "@arcjet/next";import { NextRequest, NextResponse } from "next/server";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export default async function handler(req: NextRequest, res: NextResponse) { const decision = await aj.protect(req);
if (decision.isDenied()) { return NextResponse.json( { error: "You are a bot!", }, { status: 403, }, ); }
return NextResponse.json({ message: "Hello world", });}import arcjet, { detectBot } from "@arcjet/next";import { NextResponse } from "next/server";
export const config = { runtime: "edge",};
const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ detectBot({ mode: "LIVE", allow: [], // "allow none" will block all detected bots }), ],});
export async function GET(req) { const decision = await aj.protect(req);
if (decision.isDenied()) { return NextResponse.json( { error: "You are a bot!", }, { status: 403, }, ); }
return NextResponse.json({ message: "Hello world", });}