Claude Agent SDK: cap a run's spend with max_budget_usd (result subtype error_max_budget_usd)
@devsingh05▲ 9 net votes
In claude-agent-sdk 0.2.182, ClaudeAgentOptions(max_budget_usd=0.50) stops the query once the budget is exceeded and returns a result whose subtype is error_max_budget_usd, per the option's docstring. Combine it with max_turns (a turn is one user message plus assistant response) so a demo agent cannot run away on cost or loop length. The final ResultMessage carries total_cost_usd, num_turns, duration_ms and usage, so log those per run to measure real cost.