Frameworks
Express route handler
klaro.wrap() works on any async function -- it doesn't care whether the caller is a server action, a route handler, or a plain script.
← All recipes
import express from "express";
import { Klaro, retries, secrets, logging } from "@klaroshield/sdk";
import OpenAI from "openai";
const app = express();
const openai = new OpenAI();
const klaro = new Klaro()
.use(retries({ max: 3 }))
.use(secrets({ mode: "mask" }))
.use(logging({ format: "pretty" }));
const chat = klaro.wrap(openai.chat.completions.create.bind(openai.chat.completions));
app.post("/api/chat", async (req, res) => {
const result = await chat({ model: "gpt-4o-mini", messages: req.body.messages });
res.json(result);
});Checked against the shipped @klaroshield/sdk API. Full docs at klaro.services/klaroshield/docs.