import { createGuard } from "llmbrake"; const guard = createGuard({ budgetUsd: (ctx) => ctx.plan === "pro" ? 20 : 2, downgradeAt: 0.8, downgradeMap: { "gpt-5.5": "gpt-5.4-mini" }, }); const chat = openai.chat.completions; const create = guard.wrap(chat.create.bind(chat)); await create({ model: "gpt-5.5", messages }, { customerId: user.id, plan: user.plan }); // at the cap → throws BudgetExceededError
Wrap once
One line around your OpenAI-compatible create() call. Streaming usage is captured too.