Node.js SDK
Full reference for the @nyraxis/sdk npm package.
Node.js SDK
npm install @nyraxis/sdkQuick Start
import { NyraxisClient } from "@nyraxis/sdk";
const client = new NyraxisClient({
apiKey: process.env.NYRAXIS_API_KEY!,
});
const result = await client.evaluate({
input: "User message to check",
});
if (!result.allowed) {
console.log("Blocked:", result.violations);
}Configuration
const client = new NyraxisClient({
apiKey: string; // Required: your API key
baseUrl?: string; // Default: "https://api.nyraxis.io"
timeout?: number; // Default: 30000ms
});Evaluate
const result = await client.evaluate({
input: string; // Required: text to evaluate
output?: string; // Optional: model output
policies?: string[]; // Optional: specific policies
mode?: "thorough" | "fast";
});Response
{
allowed: boolean;
violations: Array<{
policy: string;
score: number;
threshold: number;
severity: "low" | "medium" | "high" | "critical";
description: string;
}>;
latencyMs: number;
}Usage with Express
import express from "express";
import { NyraxisClient } from "@nyraxis/sdk";
const app = express();
const nyraxis = new NyraxisClient({ apiKey: process.env.NYRAXIS_API_KEY! });
app.post("/chat", async (req, res) => {
const { message } = req.body;
const check = await nyraxis.evaluate({ input: message });
if (!check.allowed) {
return res.status(422).json({
error: "Message blocked",
violations: check.violations,
});
}
// proceed with LLM call...
});Usage with Vercel AI SDK
import { NyraxisClient } from "@nyraxis/sdk";
import { openai } from "@ai-sdk/openai";
import { streamText } from "ai";
const nyraxis = new NyraxisClient({ apiKey: process.env.NYRAXIS_API_KEY! });
export async function POST(req: Request) {
const { messages } = await req.json();
const lastMessage = messages[messages.length - 1].content;
const check = await nyraxis.evaluate({ input: lastMessage });
if (!check.allowed) {
return new Response("Message blocked by policy", { status: 422 });
}
const result = streamText({
model: openai("gpt-4o"),
messages,
});
return result.toDataStreamResponse();
}Error Handling
try {
const result = await client.evaluate({ input: text });
} catch (error) {
if (error instanceof NyraxisError) {
// API error (rate limit, auth, etc.)
console.error(error.statusCode, error.message);
}
// Network error — fail open by default
}TypeScript Types
All types are exported:
import type {
EvaluateRequest,
EvaluateResponse,
Violation,
NyraxisClientOptions,
} from "@nyraxis/sdk";