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

Documentation

JavaScript SDK

The SDK is published as @behalfid/sdk and uses fetch, so it works in Node 18+ without extra dependencies.

Install

terminal
npm install @behalfid/sdk

Initialize

behalf.ts
import { BehalfID } from "@behalfid/sdk";

export const behalf = new BehalfID({
  apiKey: process.env.BEHALFID_API_KEY!,
});

Verify before execution

enforce.ts
const decision = await behalf.verify({
  agentId: "agent_xxx",
  action: "deploy_production",
  vendor: "vercel.com",
});

if (!decision.allowed) {
  throw new Error(`Blocked: ${decision.reason}`);
}

// Safe to proceed

Create a permission

permission.ts
await behalf.createPermission({
  agentId: "agent_xxx",
  action: "deploy_production",
  resource: "vercel.com",
  requiresApproval: true,
});