Skip to content

BudgetConfig

Configuration for the guard.budget() middleware.

optional fallbackPricing?: ModelPricing

Fallback pricing for models not in the default or custom table.


limit: number

Maximum USD cost per session.


optional onLimit?: "error" | "stop" | ((ctx, cost) => string | void)

What to do when the budget is exceeded.

  • "error" (default): throw BudgetExceededError
  • "stop": graceful stop — skip LLM call, turn ends with empty text
  • callback: developer decides — return string for final text, void for empty, or throw

optional pricing?: Record<string, ModelPricing>

Per-model pricing override (USD per 1M tokens). Merged with built-in defaults.