Documentation
Quickstart Guide
Add Guard to your app in minutes. You’ll create an API key, install the SDK, and protect routes using /check.
1. Create an API key
In the Guard dashboard, go to Keys → Create New Key. Copy the full token (you'll only see it once).
Keep this key server-side. Don't expose it in client-side code.
Guard API Base URL
This is the URL your SDK will communicate with:
https://guard-api-f45p.onrender.com
2. Install the SDK
npm i @shammy911/guard-sdk
3. Use it in your backend
The SDK calls your hosted Guard API. Since /check is public now, you only send x-api-key.
import { GuardClient } from "@shammy911/guard-sdk";
const guard = new GuardClient({
baseUrl: process.env.GUARD_URL!, // e.g. https://guard-api-****.onrender.com
apiKey: process.env.GUARD_API_KEY!, // your Guard key (store server-side)
timeoutMs: 800,
failClosed: true, // recommended for security endpoints
});
export async function protectRequest(route: string, method?: string) {
const decision = await guard.check(route, method);
if (!decision.allowed) {
// block request
return { ok: false, reason: decision.reason };
}
return { ok: true };
}4. Example: Next.js API route
import { NextResponse } from "next/server";
import { GuardClient } from "@shammy911/guard-sdk";
const guard = new GuardClient({
baseUrl: process.env.GUARD_URL!,
apiKey: process.env.GUARD_API_KEY!,
failClosed: true,
});
export async function POST(req: Request) {
const decision = await guard.check("/api/login", "POST");
if (!decision.allowed) {
return NextResponse.json(
{ error: "Blocked", reason: decision.reason },
{ status: 429 }
);
}
// continue login...
return NextResponse.json({ ok: true });
}Tip: Call Guard on security-sensitive endpoints first: login, signup, password reset, OTP verify, payment endpoints, etc.