Frameworks
Cloudflare Workers fetch handler
Klaro is pure JS with no Node-only APIs in its call path other than local storage (which reads/writes relative to process.cwd() -- skip logging()'s file persistence on Workers and use format: "silent" or "json" piped to your own sink instead.
← All recipes
import { Klaro, retries, secrets } from "@klaroshield/sdk";
import OpenAI from "openai";
export default {
async fetch(request: Request, env: { OPENAI_API_KEY: string }) {
const openai = new OpenAI({ apiKey: env.OPENAI_API_KEY });
const klaro = new Klaro().use(retries({ max: 2 })).use(secrets({ mode: "mask" }));
const chat = klaro.wrap(openai.chat.completions.create.bind(openai.chat.completions));
const { messages } = await request.json<{ messages: unknown }>();
const result = await chat({ model: "gpt-4o-mini", messages });
return Response.json(result);
},
};Checked against the shipped @klaroshield/sdk API. Full docs at klaro.services/klaroshield/docs.