← nopea.tech
ScaneaConsenteaMaskeaBundlesPricing
Frameworks

Fastify route handler

Same wrap, Fastify's handler signature instead of Express's.

← All recipes
import Fastify from "fastify";
import { Maskea, retries, pii } from "@nopeatech/maskea";
import OpenAI from "openai";

const fastify = Fastify();
const openai = new OpenAI();

const maskea = new Maskea().use(retries({ max: 3 })).use(pii({ mode: "mask" }));
const chat = maskea.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 @nopeatech/maskea API. Full docs at nopea.tech/maskea/docs.

More in Frameworks

Express route handler →NestJS injectable service →Next.js App Router API route →Mask PII in a Next.js server action →