Reference

TypeScript SDK Reference

Node.js SDK API — AgentTrustClient, wrap(), and types.

TypeScript SDK Reference

Overview

The TypeScript/Node.js SDK (agentrust-sdk on npm) provides AgentTrustClient, wrap(), and loadConfig() for Node.js services.

Why It Matters

Node.js backends, Express APIs, and serverless functions need native TypeScript governance integration.

Prerequisites

npm install agentrust-sdk

Node.js ≥ 18. Zero runtime dependencies.

Step-by-Step Guide

Imports

import {
  AgentTrustClient,
  loadConfig,
  BlockedError,
  GatewayError,
} from 'agentrust-sdk';

AgentTrustClient

const client = new AgentTrustClient({
  baseUrl: process.env.AGENTRUST_GATEWAY_URL,
  apiKey: process.env.AGENTRUST_API_KEY,
  timeout: 10000,
  failureMode: 'open',  // 'open' | 'closed'
});

const result = await client.validate({
  agentId: 'my-agent',
  user: 'alice',
  input: 'user query',
  output: { answer: 'response' },
  framework: 'Custom',
});

wrap() helper

const safeFn = client.wrap(
  'my-agent',
  async (user: string, input: string) => {
    return { answer: await callLlm(input) };
  },
  { blockOnBlock: true },
);

loadConfig()

const config = loadConfig();  // reads AGENTRUST_* env vars
const client = new AgentTrustClient(config);

Environment variables

VariableDefault
AGENTRUST_GATEWAY_URLhttp://localhost:8000
AGENTRUST_API_KEY
AGENTRUST_ENABLEDtrue
AGENTRUST_FAILURE_MODEopen
AGENTRUST_TIMEOUT_MS10000

Limitations vs Python SDK

FeaturePythonTypeScript
Embedded gateway
Queue mode
Framework adapters
Auto-instrument
CLI
wrap() helper

Examples

See sdks/typescript/examples/basic.ts and express-middleware.ts.

Best Practices

  • Use AGENTRUST_API_KEY (not AGENTRUST_KEY)
  • Set blockOnBlock: true for high-stakes endpoints
  • Share one AgentTrustClient instance per process