Docs / Integrations
TypeScript SDK
Using @ztechnium/rai-sdk from Node.js, including what needs version 0.2.0.
npm currently serves 0.1.1. The repository is at 0.2.0. Install from GitHub for the 0.2.0 methods marked below.
npm install @ztechnium/rai-sdk # 0.1.1
npm install github:ztechnium/rai-typescript-sdk # 0.2.0Module format
The package is CommonJS. TypeScript that compiles to CommonJS can use a normal import. In an ES module use createRequire; both static and dynamic import fail with ERR_PACKAGE_PATH_NOT_EXPORTED on 0.1.1.
import { RAIClient, RAIError } from "@ztechnium/rai-sdk";import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const { RAIClient, RAIError } = require("@ztechnium/rai-sdk");Client
const client = new RAIClient({
baseUrl: process.env.RAI_BASE_URL!,
apiKey: process.env.RAI_AGENT_KEY!, // server side only
integrationId: process.env.RAI_INTEGRATION_ID!,
timeoutMs: 30000,
failClosed: true,
});| Method | Version |
|---|---|
client.health(), client.heartbeat(), client.startSession() | 0.1.1 |
client.reportExecution(), client.request() | 0.1.1 |
session.observeInput(), session.authorizeAction(), session.observeOutput(), session.end() | 0.1.1 |
decision.reportExecution() | 0.1.1 |
client.getDecision(), client.getApprovalStatus() | 0.2.0 |
session.authorizeDataAccess() | 0.2.0 |
session.recordUsage(), recordModelCall(), completeMeteringSpan() | 0.2.0 |
delegationId on startSession() | 0.2.0 |
Decisions
const decision = await session.authorizeAction({
tool: "place_order",
parameters: { amount: 250, currency: "USD" },
idempotencyKey: orderId,
});
if (decision.allowed) {
const reference = await placeOrder();
await decision.reportExecution(client, {
status: "SUCCEEDED",
externalExecutionId: reference,
});
}A policy denial is a decision, not an exception. HTTP failures and fail-closed transport errors throw RAIError.
On 0.1.1, poll approvals with client.request("GET", "/sdk/v1/approvals/" + decision.approvalRequestId).
Source: ztechnium/rai-typescript-sdk.