Integrations
OpenAI
Gate OpenAI function calls and tool-use requests through Lelu before they execute. Works with the Assistants API, Chat Completions with tools, and the Agents SDK.
Installation
terminal
npm install lelu-agent-auth openai
Chat Completions with tool calls
After the model returns a tool_calls response, authorize each call through Lelu before executing the underlying function.
agent.ts
import OpenAI from "openai";
import { createClient } from "lelu-agent-auth";
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const lelu = createClient({ apiKey: process.env.LELU_API_KEY! });
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages,
tools,
});
for (const call of response.choices[0].message.tool_calls ?? []) {
const decision = await lelu.authorize({
tool: call.function.name,
context: call.function.arguments,
});
if (decision.decision === "deny") {
throw new Error(`Tool ${call.function.name} was denied: ${decision.reason}`);
}
if (decision.decision === "human_review") {
await waitForApproval(decision.requestId); // your approval flow
}
// safe to execute
await dispatchTool(call);
}OpenAI Agents SDK
Wrap each tool in a Lelu guard using the withLelu helper.
agent.ts
import { Agent, tool } from "@openai/agents";
import { withLelu } from "lelu-agent-auth/openai";
const sendEmail = withLelu(
tool({
name: "send_email",
description: "Send an email to a user",
parameters: z.object({ to: z.string(), body: z.string() }),
execute: async ({ to, body }) => sendMailActual(to, body),
})
);
const agent = new Agent({ tools: [sendEmail] });Environment variables
.env
OPENAI_API_KEY=sk-... LELU_API_KEY=lelu_sk_...