Budgeting & cost
Handle a budget cap without crashing
budget() throws once the monthly cap is hit by default -- pass onExceeded to decide what happens instead (log it, alert, degrade gracefully).
← All recipes
import { Maskea, budget } from "@nopeatech/maskea";
const maskea = new Maskea().use(
budget({
maxMonthlyUsd: 50,
onExceeded: (spentUsd, capUsd) => {
console.warn(`Over budget: $${spentUsd.toFixed(2)} of $${capUsd} -- consider a cheaper model.`);
},
})
);Checked against the shipped @nopeatech/maskea API. Full docs at nopea.tech/maskea/docs.