← Documentation

Vercel AI SDK Integration

Govern Vercel AI SDK, OpenAI, and Anthropic usage with TrustGate in Node.js.

Install

npm install @trustgateai/sdk

Configure

Initialize TrustGate once at application startup:

const { TrustGate } = require('@trustgateai/sdk');

new TrustGate({
  apiKey: process.env.TRUSTGATE_API_KEY,
});

Use

Use the Vercel AI SDK or any OpenAI/Anthropic client as usual. Traffic is automatically routed through TrustGate for governance, logging, and cost control.

const { TrustGate } = require('@trustgateai/sdk');
const client = new TrustGate({ apiKey: process.env.TRUSTGATE_API_KEY }).openai();

// 3. Execute request with Agentic Context
const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are an autonomous refund agent." },
    { role: "user", content: "Process refund for order 9921" }
  ],
}, {
  // Inject TrustGate Agentic Context via headers
  headers: {
    "X-Agent-Trace-Id": "workflow_refund_9921", // Groups multi-step calls into one trace
    "X-Agent-Policy": "strict_retry_block",     // Prevents infinite hallucination loops
    "X-Vault-Decrypt": "true"                   // Required for PII redaction
  }
});

console.log("Response:", response.choices[0].message.content);

Next steps