CL
Clausgap
/Docs

Vercel AI SDK

bash
npm install @clausgap/vercel-ai
ℹ

Private beta. The SDK packages aren't on the public registries yet. Access comes with onboarding — email hello@clausgap.dev.

Two integration patterns: guard an individual tool's execute function, or intercept every tool call at the model layer with a LanguageModelV1Middleware — useful when tools come from a provider you don't define yourself.

typescript
// Option 1: guard a single tool
import { tool, generateText } from "ai"
import { z } from "zod"
import { guardedTool } from "@clausgap/vercel-ai"

const searchTool = guardedTool(
  tool({
    description: "Search the web",
    parameters: z.object({ query: z.string() }),
    execute: async ({ query }) => fetchResults(query),
  }),
  {
    controlUrl: "http://localhost:8080",
    apiKey: process.env.CLAUSGAP_API_KEY!,
    agentRole: "researcher",
    toolName: "web_search",
  }
)

const result = await generateText({
  model: openai("gpt-4o"),
  tools: { search: searchTool },
  prompt: "Search for the latest AI news",
})


// Option 2: guard every tool call at the model layer
import { wrapLanguageModel } from "ai"
import { createClausgapMiddleware } from "@clausgap/vercel-ai"

const guardedModel = wrapLanguageModel({
  model: openai("gpt-4o"),
  middleware: createClausgapMiddleware({
    controlUrl: "http://localhost:8080",
    apiKey: process.env.CLAUSGAP_API_KEY!,
    agentRole: "analyst",
    onDeny: "skip", // or "throw" (default) to stop generation on a denial
  }),
})

Escrow holds

A policy's escrow rule works the same way here as everywhere else — see the escrow flow →

Use the agent's own key

Give the integration the agent's own key — registered with POST /v1/keyless/api-keys, the same key the proxy accepts — and set CLAUSGAP_TENANT_ID to your tenant ID. The key then fixes the agent's role and ID (the configured role must match it) and can only evaluate tool calls: it can't change policies or issue keys. A tenant API key also works, but lets the agent name any role, and Discovery Mode only lets calls through for agent keys. Set CLAUSGAP_ENVIRONMENT and CLAUSGAP_SCOPES to match your proxy's, if you use them. See agent keys →