Arcjet is the runtime security platform that ships with your AI code. Stop bots and automated attacks from burning your AI budget, leaking data, or misusing tools with Arcjet's AI security building blocks. Every feature works with any Astro application.
This is the Arcjet SDK for Astrorequest protection —
use it to protect HTTP route handlers and API endpoints. If you need to protect
AI agent tool calls, MCP server handlers, or background jobs (anything without
an HTTP request), see @arcjet/guard.
Getting started
Quick setup with an AI agent
Log in with the CLI:
npx @arcjet/cli auth login
Install the request protection skill to give your coding agent the docs it needs:
Detect and block prompt injection attacks — attempts to override your AI
model's instructions — before they reach your model. Pass the user's message
via detectPromptInjectionMessage on each protect() call.
Arcjet allows you to configure a list of bots to allow or deny. Specifying
allow means all other bots are denied. An empty allow list blocks all bots.
Available categories: CATEGORY:ACADEMIC, CATEGORY:ADVERTISING,
CATEGORY:AI, CATEGORY:AMAZON, CATEGORY:APPLE, CATEGORY:ARCHIVE,
CATEGORY:BOTNET, CATEGORY:FEEDFETCHER, CATEGORY:GOOGLE,
CATEGORY:META, CATEGORY:MICROSOFT, CATEGORY:MONITOR,
CATEGORY:OPTIMIZER, CATEGORY:PREVIEW, CATEGORY:PROGRAMMATIC,
CATEGORY:SEARCH_ENGINE, CATEGORY:SLACK, CATEGORY:SOCIAL,
CATEGORY:TOOL, CATEGORY:UNKNOWN, CATEGORY:VERCEL,
CATEGORY:WEBHOOK, CATEGORY:YAHOO. You can also allow or deny
specific bots by name.
import arcjet, { detectBot } from"@arcjet/astro";
// In astro.config.mjs:arcjet({
rules: [
detectBot({
mode: "LIVE",
allow: [
"CATEGORY:SEARCH_ENGINE",
// See the full list at https://arcjet.com/bot-list
],
}),
],
});
// In your API route:import { isSpoofedBot } from"@arcjet/inspect";
import aj from"arcjet:client";
const decision = await aj.protect(request);
if (decision.isDenied() && decision.reason.isBot()) {
returnResponse.json({ error: "No bots allowed" }, { status: 403 });
}
// Verifies the authenticity of common bots using IP data.if (decision.results.some(isSpoofedBot)) {
returnResponse.json({ error: "Forbidden" }, { status: 403 });
}
Bot categories
Bots can be configured by category and/or by specific
bot name. For example, to allow search engines and the OpenAI
crawler, but deny all other bots:
Bots claiming to be well-known crawlers (e.g. Googlebot) are verified by
checking their IP address against known IP ranges. If a bot fails verification,
it is labeled as spoofed. Use isSpoofedBot from @arcjet/inspect to check:
Arcjet supports token bucket, fixed window, and sliding window algorithms.
Token buckets are ideal for controlling AI token budgets — set capacity to
the max tokens a user can spend, refillRate to how many tokens are restored
per interval, and deduct tokens per request via requested in protect().
The interval accepts strings ("1s", "1m", "1h", "1d") or seconds as
a number. Use characteristics to track limits per user instead of per IP.
import arcjet, { tokenBucket } from"@arcjet/astro";
// In astro.config.mjs:arcjet({
characteristics: ["userId"], // Track per userrules: [
tokenBucket({
mode: "LIVE",
refillRate: 2_000, // Refill 2,000 tokens per hourinterval: "1h",
capacity: 5_000, // Maximum 5,000 tokens in the bucket
}),
],
});
// In your API route:const decision = await aj.protect(request, {
userId: "user-123",
requested: estimate, // Number of tokens to deduct
});
if (decision.isDenied() && decision.reason.isRateLimit()) {
returnResponse.json({ error: "Rate limit exceeded" }, { status: 429 });
}
Sensitive information detection
Detect and block PII in request content. Pass the content to scan via
sensitiveInfoValue on each protect() call. Built-in entity types:
CREDIT_CARD_NUMBER, EMAIL, PHONE_NUMBER, IP_ADDRESS. You can also
provide a custom detect callback for additional patterns.
import arcjet, { sensitiveInfo } from"@arcjet/astro";
// In astro.config.mjs:arcjet({
rules: [
sensitiveInfo({
mode: "LIVE", // Blocks requests. Use "DRY_RUN" to log onlydeny: ["CREDIT_CARD_NUMBER", "EMAIL", "PHONE_NUMBER"],
}),
],
});
// In your API route:const decision = await aj.protect(request, {
sensitiveInfoValue: userMessage, // The text content to scan
});
if (decision.isDenied() && decision.reason.isSensitiveInfo()) {
returnResponse.json(
{ error: "Sensitive information detected" },
{ status: 400 },
);
}
Shield WAF
Protect your application against common web attacks, including the OWASP
Top 10.
Arcjet enriches every request with IP metadata. Use these helpers to make
policy decisions based on network signals:
const decision = await aj.protect(request);
if (decision.ip.isHosting()) {
// Requests from cloud/hosting providers are often automated.// https://docs.arcjet.com/blueprints/vpn-proxy-detectionreturnResponse.json({ error: "Forbidden" }, { status: 403 });
}
if (decision.ip.isVpn() || decision.ip.isProxy() || decision.ip.isTor()) {
// Handle VPN/proxy traffic according to your policy
}
// Access geolocation and network detailsconsole.log(decision.ip.country, decision.ip.city, decision.ip.asn);
Custom characteristics
Track and limit requests by any stable identifier — user ID, API key, session,
etc. — rather than IP address alone.
// In astro.config.mjs:arcjet({
characteristics: ["userId"], // Declare at the SDK levelrules: [
tokenBucket({
mode: "LIVE",
refillRate: 2_000,
interval: "1h",
capacity: 5_000,
}),
],
});
// Pass the characteristic value at request timeconst decision = await aj.protect(request, {
userId: "user-123", // Replace with your actual user IDrequested: estimate,
});
Use withRule() for route-specific rules on top of the base rules
configured in astro.config.mjs. The SDK caches decisions and configuration,
so this is more efficient than creating a new instance per request.
Arcjet runtime security SDK for Astro — bot protection, rate limiting, prompt injection detection, PII blocking, and WAF
The npm package @arcjet/astro receives a total of 99 weekly downloads. As such, @arcjet/astro popularity was classified as not popular.
We found that @arcjet/astro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.
Package last updated on 09 Jun 2026
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.