Documentation
BehalfID Site Guard
BehalfID Site Guard lets website owners check whether an incoming request is from an authorized AI agent before executing sensitive workflows.
What it does
Site Guard lets you add BehalfID verification to your website's middleware, edge worker, or proxy. Requests from AI agents must carry a valid passport token and the action they want to perform.
Middleware pattern
import { checkSiteGuard } from "@behalfid/sdk";
export async function middleware(request: Request) {
const passportToken = request.headers.get("X-BehalfID-Passport");
const action = request.headers.get("X-BehalfID-Action");
if (passportToken && action) {
const decision = await checkSiteGuard({
passportToken,
action,
resource: new URL(request.url).pathname,
});
if (!decision.allowed) {
return new Response("Forbidden by BehalfID", { status: 403 });
}
}
return fetch(request);
}