veto.authorize is the primary method. It checks whether an agent is permitted to call a tool with the given parameters and returns an AuthorizationResult.
import { VetoError, UnauthorizedError, RateLimitError } from "@useveto/node";try { const result = await veto.authorize("support-bot", "send_email", { to: "user@example.com", }); if (!result.allowed) { console.warn(`Denied: ${result.reason}`); }} catch (error) { if (error instanceof RateLimitError) { // back off and retry console.error(`Rate limited — retry after ${error.retryAfterMs}ms`); await sleep(error.retryAfterMs); } else if (error instanceof UnauthorizedError) { // bad or expired API key console.error("Invalid API key — check VETO_API_KEY"); } else if (error instanceof VetoError) { // any other Veto error (timeout, network, server error) console.error(`Veto error [${error.code}]: ${error.message}`); }}
VetoError also covers TIMEOUT (status 408) and NETWORK_ERROR (status 0) when the Veto API is unreachable.
By default, if the Veto API is unreachable (network error or timeout), the SDK denies the request. This ensures your agent cannot take unauthorized actions simply because authorization is unavailable.When using MCP middleware (createVetoGuard or vetoMiddleware), you can override this with the onError option:
import { VetoClient, createVetoGuard } from "@useveto/node";const veto = new VetoClient({ apiKey: process.env.VETO_API_KEY! });// Default — fail-closed (recommended for production)const protect = createVetoGuard(veto, { agentId: "my-agent", onError: "deny",});// Fail-open — allow tool calls even when Veto is unreachableconst protect = createVetoGuard(veto, { agentId: "my-agent", onError: "allow",});
onError: "allow" lets tool calls proceed when Veto is unreachable. This is not recommended for production — a network partition becomes a security gap.