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-sdkNode.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
| Variable | Default |
|---|---|
AGENTRUST_GATEWAY_URL | http://localhost:8000 |
AGENTRUST_API_KEY | — |
AGENTRUST_ENABLED | true |
AGENTRUST_FAILURE_MODE | open |
AGENTRUST_TIMEOUT_MS | 10000 |
Limitations vs Python SDK
| Feature | Python | TypeScript |
|---|---|---|
| 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(notAGENTRUST_KEY) - Set
blockOnBlock: truefor high-stakes endpoints - Share one
AgentTrustClientinstance per process