Arcjet
Use Arcjet for MainSDK rate limits and bot protection - setup, main.yaml, limits.rate, local testing and swapping.
Arcjet is a security SDK for rate limiting and bot protection, and one of the drivers behind limits. Pick it when you want rate decisions and bot detection from a service rather than counters you keep yourself.
Interfaces it serves
Pick Arcjet in main.yaml for any of these. Your calls stay the same, and you can swap later.
limitsBuilding for 0.3Driver arcjet Arcjet
later
limits:
driver: arcjetSwap to another provider
Before you start
- Create an Arcjet account and a site for your app.
- Copy the site's key into your secrets manager.
Configure
limits:
driver: arcjet # [to be decided] how the driver takes its key; suggested name ARCJET_KEYUse it
import { auth, limits } from "mainsdk";
export async function POST(req: Request) {
const session = await auth.require(req);
const ok = await limits.rate(`export:${session.user.id}`, { per: "1m", max: 5 });
if (!ok) return new Response("Too many requests", { status: 429 });
return Response.json({ started: true });
}Local development and testing
Use the builtin driver in development. In tests, createTestApp() from @mainsdk/testing runs limits on an in-memory fake, and clock.advance() resets windows without waiting. chaos.on("limits", { outage: true }) simulates Arcjet being unreachable.
What MainSDK adds on top
- Rate limits on sign-in, sign-up, password reset and AI calls by default.
- Abuse and bot protection as part of the interface.
Limits and notes
limitshas no spec yet, so how the bot protection and the IP allowlist per customer org map onto Arcjet is not decided yet.- Limit by user or organisation ID rather than by personal data such as an email address.
Swap to or from it
limits:
driver: arcjet # was builtinYour calls stay the same. Counters start fresh on the new driver.
FAQ
Does Arcjet replace sign-in limits? No. Those are on by default whichever driver you use.
Can I use Arcjet and Upstash together? One limits driver is active at a time.
Next
Open questions
Was this page helpful?