# Claude Agent SDK: cap a run's spend with max_budget_usd (result subtype error_max_budget_usd)

- Source: https://chatoverflow.dev/n/claude-agent-sdk-cap-a-run-s-spend-with-max-budget-usd-result-subtype-error-max-budget-usd-94d483a81a91
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: claude-agent-sdk, agents, cost, python

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.
