Protect Tools
Start protecting executable tools with the Veto TypeScript SDK.
protect() is the shortest TypeScript path for executable tool objects. It wraps execute, func, or invoke, calls Veto Cloud before the tool runs, and throws before execution when a call is denied or needs approval.
Set VETO_API_KEY, or pass apiKey directly:
export VETO_API_KEY=veto_...import { protect } from "veto-sdk";
const tools = await protect([
{
name: "issue_refund",
description: "Issue a customer refund",
execute: async ({ amount_usd }: { amount_usd: number }) => {
return { refunded: amount_usd };
},
},
]);Explicit Client
Use Veto.init() when you want to reuse one client for Guard, Charter, tool registration, and approvals:
import { Veto } from "veto-sdk";
const veto = await Veto.init({
baseUrl: process.env.VETO_API_URL ?? "https://api.veto.so",
apiKey: process.env.VETO_API_KEY!,
});
const tools = veto.wrap([
{
name: "prod_db_query",
execute: async ({ sql }: { sql: string }) => runQuery(sql),
},
]);Denials
Denied and approval-required calls throw ToolCallDeniedError before your tool executes.
import { ToolCallDeniedError } from "veto-sdk";
try {
await tools[0].execute({ amount_usd: 900 });
} catch (error) {
if (error instanceof ToolCallDeniedError) {
console.error(error.toolName, error.decision, error.message);
}
}Approval Waiting
By default, require_approval does not execute the tool. To wait for an approval decision, opt in:
const tools = await protect(existingTools, {
apiKey: process.env.VETO_API_KEY!,
approvalMode: "wait",
approvalTimeoutMs: 10 * 60 * 1000,
});Notes
protect()accepts one executable tool or an array.- Supported executable methods are
execute,func, andinvoke. - Schema-only tool definitions are not enough for execution-time enforcement. Use provider adapters for schemas, or use the Vercel AI SDK middleware for model-level interception.
- Missing API keys fail explicitly. The SDK does not silently fall back to unguarded allow-all execution.

