Frameworks
Fastify route handler
Same wrap, Fastify's handler signature instead of Express's.
← All recipes
import Fastify from "fastify";
import { Klaro, retries, pii } from "@klaroshield/sdk";
import OpenAI from "openai";
const fastify = Fastify();
const openai = new OpenAI();
const klaro = new Klaro().use(retries({ max: 3 })).use(pii({ mode: "mask" }));
const chat = klaro.wrap(openai.chat.completions.create.bind(openai.chat.completions));
fastify.post("/chat", async (request, reply) => {
const body = request.body as { messages: { role: string; content: string }[] };
return chat({ model: "gpt-4o-mini", messages: body.messages });
});Checked against the shipped @klaroshield/sdk API. Full docs at klaro.services/klaroshield/docs.