Skip to main content
Cap how much an agent can spend per run with ExecutionConfig(max_budget=...) — when the limit is hit, PraisonAI stops the run and raises BudgetExceededError.
Async enforcement. max_budget is now enforced on async paths (astart() / achat()) as well as sync paths. Gateway bots using async agents will receive BudgetExceededError when their configured ceiling is reached. Previously only sync dispatch enforced the limit.
Sync chat parity. The sync OpenAI chat path (agent.chat(), agent.start()) raises BudgetExceededError on a budget trip, matching the async and custom-LLM paths. Older versions could return None instead of raising.
PR #5841: the max_budget pre-call guard now uses the canonical CJK-aware token estimator. Agents that process Chinese, Japanese or Korean text will see the pre-call cost estimate rise toward the real token count; raise max_budget if a previously-passing agent starts hitting the guard.
Provider/model agents are now capped too (PR #6062). Agents built from a provider/model string (anthropic/..., mistral/..., ollama/..., openrouter/...), an llm={...} dict, a base_url, or a model object used to skip max_budget and report total_cost == 0. They now share the same accounting as OpenAI-style models, and the cap is checked on every LLM call — so it can stop a single turn partway through its tool loop.
The user sets a spend cap; the agent stops the run and raises BudgetExceededError once estimated cost exceeds the limit.
The top-level Agent(max_budget=...) shortcut was removed (PraisonAI PR #1642). Use execution=ExecutionConfig(max_budget=...) — see CLI budget handling.

Three ways to set it

Python, YAML, and the CLI all set the same ExecutionConfig.max_budget.

Quick Start

1

Set a simple USD cap

When spend reaches $0.50, the run stops with BudgetExceededError including agent name and totals.
2

Async run with budget cap

astart() raises BudgetExceededError the same way start() does — the async path now has identical pre-call guards and post-call cost accounting.
3

Warn instead of stopping

With on_budget_exceeded="warn", the agent logs a warning but continues. Default is "stop".
max_budget is enforced on both sync (start()) and async (astart()) paths as of 1.6.88+. Gateway bots that call astart() internally now honour the budget cap and raise BudgetExceededError identically to sync runs.

How It Works

Every way of building the agent’s LLM is covered: The cap is checked after each LLM call, including calls inside a tool loop:
Budget tracking adds zero overhead when max_budget is None (the default). Schedulers use the same brake — see Async Scheduler → Budget-aware Scheduling. Setting max_cost=0 on AsyncAgentScheduler is a real (zero) budget and short-circuits start() (returns False, no background task) when combined with run_immediately=True. As of PraisonAI PR #5766 the sync AgentScheduler matches this behavior on every entry point, including execute_once() (returns None) and start(run_immediately=True).

Configuration Options

ExecutionConfig

Full execution configuration reference

CLI Budget Handling

Budget limits from the CLI

Best Practices

Set max_budget on any agent that runs unattended or loops over tools. $0.25–$1.00 is a sensible starting range for research agents.
on_budget_exceeded="warn" lets you see full output while still logging when you’d have been stopped in production.
For a provider/model agent with on_budget_exceeded="stop", once it has crossed max_budget, every later chat() / achat() raises BudgetExceededError again before contacting the provider. Catching the error and retrying cannot spend more — create a new agent (or one with a higher cap) to continue.
Budget caps control spend; rate limiters control request frequency. Use both for cost-sensitive deployments.

See also: Autonomous run budget

ExecutionConfig.max_budget is one of two budget mechanisms. run_autonomous / run_autonomous_async have their own independent cap via AutonomyConfig — pick the one that matches your run type. For autonomous runs, prefer the AutonomyConfig cap — it pauses recoverably instead of raising. See Autonomy Budget.

Autonomy Budget

Spend/token kill-switch for autonomous runs

CLI Budget Handling

Set budgets from the command line

Execution Config

All execution options in one place

Gateway Spend Budget

Cap cumulative per-identity spend across runs on a shared-Agent gateway