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 { Klaro, budget } from "@klaroshield/sdk";
const klaro = new Klaro().use(
budget({
maxMonthlyUsd: 50,
onExceeded: (spentUsd, capUsd) => {
console.warn(`Over budget: $${spentUsd.toFixed(2)} of $${capUsd} -- consider a cheaper model.`);
},
})
);Checked against the shipped @klaroshield/sdk API. Full docs at klaro.services/klaroshield/docs.