Site Guard

DocsSite Guard

Simple mode on — some technical details are condensed. Switch to Dev in the nav for full API reference.

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

middleware.ts
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);
}