budget.reserveCan this call spend?
Vaern compares each reserve with the remaining budget before dispatching a model call or tool.
Read about budgetsOpen-source runtime
VaernJS is a JavaScript and TypeScript runtime for AI agents. Set a budget, record effects, and replay a run using the original script.
npm install -g @vaernjs/vaernRun inspector
run.ts
Declared tool budget
$0.03 / $0.05
Each part of the runtime answers a different question about the run.
budget.reserveVaern compares each reserve with the remaining budget before dispatching a model call or tool.
Read about budgetsjournal.jsonlThe runtime writes a hash-chained record of effects. Verify the journal and retain its final hash when you need to check it later.
Inspect the journal formatvaern replayReplay supported effects offline with their recorded results. Vaern checks whether the transcript matches.
Read about replayThe script counts local sample entries. It makes two calls to the same tool so you can see the second call stop at the budget limit. It needs no API key.
import { budget, BudgetError, tool } from "vaern:ai";
budget({ usd: 0.05 });
const count = tool({
name: "count_ready",
cost: { usd: 0.03 },
run: () => ["new", "ready", "ready", "queued"]
.filter((entry) => entry === "ready").length,
});
console.log("Ready entries:", await count.call({}));
try {
await count.call({});
} catch (error) {
if (!(error instanceof BudgetError)) throw error;
console.log("Second call blocked:", error.code);
}npm install -g @vaernjs/vaernrun.tsRun these commands from the directory where you saved the file.
vaern run run.ts
vaern journal verify latest
vaern replay latest