Integrations
Express
Validate a server request, evaluate input, and gate a buffered OpenAI response.
This server recipe uses Node SDK 1.2.9 and Express. Complete the quickstart, configure a policy for docs-integration, and save nyraxis-gate.mjs beside server.mjs.
npm install express openai @nyraxis/sdk@1.2.9Set NYRAXIS_API_KEY, NYRAXIS_BASE_URL and OPENAI_API_KEY. Run the following with node server.mjs.
import express from "express";
import OpenAI from "openai";
import { requireAllowed } from "./nyraxis-gate.mjs";
const app = express();
const model = new OpenAI();
app.use(express.json({ limit: "16kb" }));
app.post("/chat", async (req, res) => {
const input = req.body?.input;
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
return res.status(400).json({ error: "Provide 1–4000 characters" });
}
try {
await requireAllowed({ input });
const answer = await model.chat.completions.create({
model: process.env.OPENAI_MODEL || "gpt-4o-mini",
messages: [{ role: "user", content: input }],
});
const output = answer.choices[0].message.content || "";
await requireAllowed({ input, output });
return res.json({ output });
} catch (error) {
return res.status(error.name === "PolicyBlocked" ? 403 : 503)
.json({ error: error.name === "PolicyBlocked" ? "Policy blocked this request" : "Required check or model unavailable" });
}
});
app.listen(8080, "127.0.0.1");Test malformed input, safe text, synthetic blocked input, blocked output and Nyraxis failure. Confirm blocked input causes zero provider requests. This is a localhost recipe; add application authentication, authorization, rate limits and deployment logging before exposing it publicly. Do not log secrets or raw workload text in error handlers.
See Node SDK, upstream Express docs and capture settings.