Nyraxis/ docs
SDK
Developer documentation

Node.js SDK

Evaluate content and wrap supported OpenAI methods with @nyraxis/sdk 1.2.9.

Install

Use a server-side Node.js project. Never place the Nyraxis key in a browser bundle.

Terminal
npm install @nyraxis/sdk@1.2.9

Evaluate content

evaluate.mjs
import { NyraxisClient } from "@nyraxis/sdk";

const apiKey = process.env.NYRAXIS_API_KEY;
const baseUrl = process.env.NYRAXIS_BASE_URL;
if (!apiKey || !baseUrl) throw new Error("Configure the Nyraxis environment");

const client = new NyraxisClient({
  apiKey, baseUrl, agentName: "support-agent", timeout: 30_000,
});
const result = await client.evaluate({
  input: "What are your support hours?",
  capture_mode: "metadata",
});
if (result.evaluation_status !== "complete"
    || (result.errors?.length ?? 0) > 0
    || result.policies_evaluated < 1) {
  throw new Error("Required evaluation did not complete");
}
console.log({ allowed: result.allowed, trace_id: result.trace_id });

Act on allowed before the protected operation. Direct evaluation does not itself stop downstream code. The client uses fetch; there is no init() or client shutdown method in this Node package.

Client options

OptionDefaultPurpose
apiKeyRequiredAn issued key; use ingest for evaluation.
baseUrlhttps://api.nyraxis.ioBackend API origin.
agentNameUnsetDefault agent name for evaluations.
timeout30000Request timeout in milliseconds.

Evaluation arguments

evaluate() accepts input (required), output, agent_name, policies, mode, no_trace, and capture_mode. mode is "thorough" or "fast". The request fields use snake_case, even though constructor options use camelCase.

Response shape

Response fields
import type { EvaluateResponse, Violation, EvaluateParams } from "@nyraxis/sdk";

const requiredResponseFields: Array<keyof EvaluateResponse> = [
  "allowed", "violations", "latency_ms", "mode", "policies_evaluated",
];

Each violation has policy_type, severity, description, and details. The response also carries trace_id, evaluation_status, errors, policy_versions, and capture_mode where returned by the API. There is no latencyMs, isSafe, or blocked response property. For a required check, missing completion information must fail your application's acceptance check.

OpenAI pre-call wrapper

protected-openai.mjs
import OpenAI from "openai";
import { NyraxisClient, enforce, GovernanceBlocked } from "@nyraxis/sdk";

if (!process.env.NYRAXIS_API_KEY || !process.env.NYRAXIS_BASE_URL) {
  throw new Error("Configure the Nyraxis environment");
}
const client = new NyraxisClient({
  apiKey: process.env.NYRAXIS_API_KEY,
  baseUrl: process.env.NYRAXIS_BASE_URL,
  agentName: "support-agent",
});
const model = new OpenAI();
enforce(model, { client, behavior: "enforce", depth: "thorough", requireComplete: true });
try {
  const response = await model.chat.completions.create({
    model: process.env.OPENAI_MODEL || "gpt-4o-mini",
    messages: [{ role: "user", content: "What are your support hours?" }],
  });
  console.log({ completed: Boolean(response.id) });
} catch (error) {
  if (error instanceof GovernanceBlocked) {
    console.log({ blocked: true });
  } else {
    throw error;
  }
}

Install openai separately. The wrapper's behavior is enforce, monitor, or disabled; depth is the separate API evaluation mode. An evaluator failure propagates instead of automatically allowing a model call. Supported generated output is not automatically buffered and blocked by this input wrapper.

Error handling

NyraxisError exposes statusCode for API failures. GovernanceBlocked carries violations and the evaluation response for a policy block. Malformed decisions, access denials, network failures, and timeouts must stop required operations; do not log raw response bodies or credentials.

Tracing and streaming

trace(name, attributes?, fn) and traced(name, fn, attributes?) group work using OpenTelemetry. The application owns its tracer provider, context manager, processor, exporter, and shutdown. Without that setup, wrapping work does not prove export.

Version 1.2.9 preserves parent span lifetime across supported streaming consumption and early close. Close or cancel abandoned streams. Already-emitted tokens cannot be recalled by a later output evaluation. See tracing and Vercel AI SDK.

On this page