このページはまだお使いの言語に翻訳されていないか、翻訳が技術レビュー待ちです。以下には英語の原文を表示しています。 英語のページを開く
Vercel AI SDK Integration
Enforce Control Zero policies in applications built with the Vercel AI SDK.
Overview
The Vercel AI SDK provides a unified interface for building AI-powered applications in TypeScript/JavaScript. Control Zero integrates through middleware that intercepts model calls and tool invocations before they execute.
Installation
Configure the Control Zero registry once: add @controlzero:registry=https://npm.controlzero.ai to your .npmrc (or run npm config set @controlzero:registry https://npm.controlzero.ai). It applies to npm install and npx for the whole @controlzero scope.
npm install @controlzero/sdk ai
Setup
import { Client } from '@controlzero/sdk';
import { generateText, streamText, tool, gateway } from 'ai';
const cz = new Client({
policy: {
rules: [
{ allow: 'llm:generate', reason: 'LLM calls are permitted' },
{ allow: 'search_web:*', reason: 'Web search is permitted' },
{ deny: 'read_database:*', reason: 'Database access is blocked' },
],
},
});
Basic Usage
Enforce Before Generation
Pass raiseOnDeny: true so a deny decision throws and blocks the AI call.
Without it, guard() returns the decision but does not stop execution.
async function generate(prompt: string, model: string = 'openai/gpt-5.4') {
// Enforce policy before the AI call
await cz.guard('llm', {
method: 'generate',
args: { model },
raiseOnDeny: true,
});
const result = await generateText({
model: gateway(model),
prompt,
});
return result.text;
}