Vercel AI SDK
Wrap any AI SDK agent so every tool call is verified.
npm install @detecte/sdk aiimport { Detecte } from "@detecte/sdk";
import { detecteWrap } from "@detecte/sdk/integrations/vercel-ai";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
const detecte = new Detecte({ apiKey: process.env.DETECTE_API_KEY! });
const guarded = detecteWrap(
{
model: openai("gpt-4o"),
tools: {
refund_order: {
description: "Refund an order",
parameters: z.object({ orderId: z.string(), amount: z.number() }),
execute: async ({ orderId, amount }) => doRefund(orderId, amount),
},
},
},
{ detecte, agentId: "agent_support_bot" }
);
const { text } = await generateText({
model: guarded.model,
tools: guarded.tools,
prompt: "Refund order ord_123 for $42.",
});When the model calls refund_order, detecteWrap calls verify() first. If blocked, the tool returns an error result back to the model loop with the policy reason — the model then continues, often gracefully informing the user it can't perform the action.
What you get
- Streaming-aware — works with both
generateTextandstreamText. - Trace IDs — every Detecte decision carries the AI SDK
toolCallIdincontext, so you can correlate from either side. - OpenTelemetry — spans are tagged with
ai.tool.nameanddetecte.decision.idwhen OTel is configured.