Frameworks
Express route handler
maskea.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 { Maskea, retries, secrets, logging } from "@nopeatech/maskea";
import OpenAI from "openai";
const app = express();
const openai = new OpenAI();
const maskea = new Maskea()
.use(retries({ max: 3 }))
.use(secrets({ mode: "mask" }))
.use(logging({ format: "pretty" }));
const chat = maskea.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 @nopeatech/maskea API. Full docs at nopea.tech/maskea/docs.