Bot protection for Nuxt
Arcjet bot detection lets you manage traffic by automated clients and bots.
What is Arcjet?
Arcjet is the runtime security platform that ships with your code. Enforce budgets, stop prompt injection, detect bots, and protect personal information with Arcjet's AI security building blocks.Quick start
Section titled “Quick start”This guide shows you how to protect your
1. Install Arcjet
Section titled “1. Install Arcjet”In your project root, install the SDK:
npx nuxt module add @arcjet/nuxtpnpm nuxt module add @arcjet/nuxtyarn nuxt module add @arcjet/nuxtThis automatically installs and configures the Arcjet Nuxt integration in your project. Learn more about how this works in the Nuxt docs. Alternatively, you can follow the manual installation instructions.
Manual installation instruction
In your project root, install the integration:
npm install @arcjet/nuxtpnpm add @arcjet/nuxtyarn add @arcjet/nuxtUpdate your Nuxt configuration file:
export default defineNuxtConfig({ arcjet: { key: process.env.ARCJET_KEY, }, compatibilityDate: "2025-07-15", devtools: { enabled: true }, modules: ["@arcjet/nuxt"],});Next, install the @arcjet/inspect
library, which provides utilities for working with the decision returned from an
Arcjet SDK:
npm add @arcjet/inspectpnpm add @arcjet/inspectyarn add @arcjet/inspect2. Set your key
Section titled “2. Set your key”Create a free Arcjet account then follow the instructions to add a site and get a key.
The Arcjet Nuxt integration reads your Arcjet key from the ARCJET_KEY
environment variable. During development, add your key to a .env file in your
project root. Nuxt automatically loads the environment variables from this file.
Learn more in the Nuxt
docs.
# Get your site key from https://console.arcjet.comARCJET_KEY=ajkey_yourkey3. Add bot protection
Section titled “3. Add bot protection”The following example returns a 403 Forbidden response for all requests from clients we are sure are automated.
Create a new server route at server/api/protected.get.ts:
// The `#arcjet` virtual module is created created when using @arcjet/nuxtimport arcjetNuxt, { detectBot } from "#arcjet";import { isSpoofedBot } from "@arcjet/inspect";
const arcjet = arcjetNuxt({ 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 e.g. Slack, Discord ], }), ],});
export default defineEventHandler(async (event) => { const decision = await arcjet.protect(event);
// Bots not in the allow list will be blocked if (decision.isDenied()) { throw createError({ statusCode: 403, statusMessage: "Forbidden", }); }
// Requests from hosting IPs are likely from bots, so they can usually be // blocked. However, consider your use case - if this is an API endpoint // then hosting IPs might be legitimate. // https://docs.arcjet.com/blueprints/vpn-proxy-detection if (decision.ip.isHosting()) { throw createError({ statusCode: 403, statusMessage: "Forbidden", }); }
// 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)) { throw createError({ statusCode: 403, statusMessage: "Forbidden", }); }
return { message: "Hello world" };});Create a new server route at server/api/protected.get.js:
// The `#arcjet` virtual module is created created when using @arcjet/nuxtimport arcjetNuxt, { detectBot } from "#arcjet";import { isSpoofedBot } from "@arcjet/inspect";
const arcjet = arcjetNuxt({ 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 e.g. Slack, Discord ], }), ],});
export default defineEventHandler(async (event) => { const decision = await arcjet.protect(event);
// Bots not in the allow list will be blocked if (decision.isDenied()) { throw createError({ statusCode: 403, statusMessage: "Forbidden", }); }
// Requests from hosting IPs are likely from bots, so they can usually be // blocked. However, consider your use case - if this is an API endpoint // then hosting IPs might be legitimate. // https://docs.arcjet.com/blueprints/vpn-proxy-detection if (decision.ip.isHosting()) { throw createError({ statusCode: 403, statusMessage: "Forbidden", }); }
// 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)) { throw createError({ statusCode: 403, statusMessage: "Forbidden", }); }
return { message: "Hello world" };});4. Start app
npm run devpnpm run devyarn run devMake a curl request from your terminal to your application. You get a 403 Forbidden response because curl is considered an automated client by default.
See the reference guide
to learn about configuring this.
curl -I http://localhost:3000/api/protectedThe requests also appear in the Arcjet dashboard.
5. Choose bots to allow or deny
Section titled “5. Choose bots to allow or deny”Arcjet maintains a list of known bots so you can choose to either only
allow specific bots
or only
deny specific bots.
Pass exactly one of allow or deny on each rule. An empty allow list
blocks every detected bot.
Bots can be identified individually or through managed categories. For more details, see Identifying bots.
Do I need to run any infrastructure, such as Redis?
No, Arcjet handles all the infrastructure for you so you don't need to worry about deploying global Redis clusters, designing data structures to track rate limits, or keeping security detection rules up to date.
What is the performance overhead?
Arcjet SDK tries to do as much as possible asynchronously and locally to minimize latency for each request. Where decisions can be made locally or previous decisions are cached in-memory, latency is usually <1ms.
When a call to the Cloud API is required, such as when tracking a rate limit in a serverless environment, there is some additional latency before a decision is made. The Cloud API has been designed for high performance and low latency, and is deployed to multiple regions around the world. The SDK will automatically use the closest region which means the total overhead is typically no more than 20-30ms, often significantly less.
What happens if Arcjet is unavailable?
Where a decision has been cached locally, such as blocking a client, Arcjet will continue to function even if the service is unavailable.
If a call to the Cloud API is needed and there is a network problem or Arcjet is unavailable, the default behavior is to fail open and allow the request. You have control over how to handle errors, including choosing to fail close if you prefer. See the reference docs for details.
How does Arcjet protect me against DDoS attacks?
Network layer attacks tend to be generic and high volume, so these are best handled by your hosting platform. Most cloud providers include network DDoS protection by default.
Arcjet sits closer to your application so it can understand the context. This is important because some types of traffic may not look like a DDoS attack, but can still have the same effect. For example, a customer making too many API requests and affecting other customers, or large numbers of signups from disposable email addresses.
Network-level DDoS protection tools find it difficult to protect against this type of traffic because they don't understand the structure of your application. Arcjet can help you to identify and block this traffic by integrating with your codebase and understanding the context of the request, such as the customer ID or the sensitivity of the API route.
Volumetric network attacks are best handled by your hosting provider. Application level attacks need to be handled by the application. That's where Arcjet helps.
What next?
Section titled “What next?”Explore
Section titled “Explore”Arcjet can be used with specific rules on individual routes or as general protection on your entire application. You can set up rate limiting for your API, minimize fraudulent registrations with the signup form protection and more.
Get help
Section titled “Get help”Need help with anything? Email support@arcjet.com to get support from our engineering team.