Node.js

On a long-running Node process you can initialize once at startup and rely on the SDK's background batching for most traffic. Still use flush() at graceful shutdown if you want to drain the queue before exit.

Initialize once

Call noryen.init() when your application boots (after loading env), not per HTTP request, unless you use worker threads or separate isolates per request.

Minimal HTTP server

server.mjs
import http from "node:http";
import { noryen } from "@noryen/sdk";
import OpenAI from "openai";
noryen.init({ apiKey: process.env.NORYEN_API_KEY! });
const openai = noryen.wrap(
new OpenAI({ apiKey: process.env.OPENAI_API_KEY! }),
);
const server = http.createServer(async (req, res) => {
if (req.method === "POST" && req.url === "/chat") {
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello" }],
});
await noryen.flush();
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(completion));
return;
}
res.writeHead(404);
res.end();
});
server.listen(3000);

For Express, Fastify, or Hono, apply the same pattern inside route handlers: wrap your provider client, handle the request, then await noryen.flush() before sending the response if you want request-scoped delivery guarantees.

Wrappers · Installation overview