Skip to content
/docs

Framework Examples

Current TypeScript examples for Veto Guard, Charter, Vercel AI SDK, and provider adapters.

These examples use the current veto-sdk surface. Set VETO_API_KEY before running them.

export VETO_API_KEY=veto_...

Executable Tools

Use protect() for executable tool objects.

import { protect } from "veto-sdk";

const tools = await protect([
  {
    name: "transfer_funds",
    description: "Transfer money to an account",
    execute: async ({ amount, to }: { amount: number; to: string }) => {
      return { transferred: amount, to };
    },
  },
]);

await tools[0].execute({ amount: 500, to: "alice" });

Vercel AI SDK

Use middleware when the model emits tool calls and the framework executes them.

import { generateText, tool, wrapLanguageModel } from "ai";
import { openai } from "@ai-sdk/openai";
import { Veto } from "veto-sdk";
import { createVetoMiddleware } from "veto-sdk/integrations/vercel-ai";
import { z } from "zod";

const veto = await Veto.init();
const model = wrapLanguageModel({
  model: openai("gpt-4.1"),
  middleware: createVetoMiddleware(veto),
});

const result = await generateText({
  model,
  tools: {
    transfer_funds: tool({
      description: "Transfer money",
      inputSchema: z.object({
        amount: z.number(),
        to: z.string(),
      }),
      execute: async ({ amount, to }) => ({ transferred: amount, to }),
    }),
  },
  prompt: "Transfer $500 to Alice",
});

Charter

Register runtime tools, then ask Charter to compile policy drafts with verification links.

import { Veto } from "veto-sdk";

const veto = await Veto.init();

await veto.registerTools([
  {
    name: "send_customer_email",
    description: "Send an email to a customer",
    parameters: [
      { name: "to", type: "string", required: true },
      { name: "body", type: "string", required: true },
    ],
  },
]);

const res = await fetch("https://api.veto.so/v1/charter/turn", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Veto-API-Key": process.env.VETO_API_KEY!,
  },
  body: JSON.stringify({
    message: "Customer emails after 10pm need review.",
    mode: "compile",
    surface: "api",
  }),
});
const turn = await res.json();

console.log(turn.verification.linkUrl);

MCP Tool Schemas

import { Veto } from "veto-sdk";

const veto = await Veto.init();

await veto.registerTools([
  {
    name: "read_file",
    description: "Read a file",
    parameters: [{ name: "path", type: "string", required: true }],
  },
]);

Provider Adapters

Use adapters for schema conversion and normalized tool-call payloads.

import {
  fromOpenAIToolCall,
  toAnthropic,
  toGoogleTool,
  toOpenAI,
} from "veto-sdk";

const tool = {
  name: "transfer_funds",
  description: "Transfer money",
  parameters: [{ name: "amount", type: "number" as const, required: true }],
};

const openAiTool = toOpenAI(tool);
const anthropicTool = toAnthropic(tool);
const geminiTool = toGoogleTool([tool]);

const normalized = fromOpenAIToolCall({
  id: "call_1",
  function: {
    name: "transfer_funds",
    arguments: "{\"amount\":500}",
  },
});

Next Steps