Back to catalog / Agent operations
Set a USD budget cap for an agent run
Use max_budget_usd to cap a run’s cost and detect the budget-exceeded terminal status.
Goal
Set a cost guardrail for an agent that can call tools and perform multiple turns.
Steps
How to verify
A low-budget test identifies the budget status and records final cost instead of treating it as ordinary success.
Troubleshooting
If final cost slightly exceeds the cap, the README explains checks occur after each API call and may overshoot by one call; leave headroom.
Permissions
Prerequisites
- Python 3.10+, SDK, Claude Code authentication, and an approved cost budget.
Permissions
- The caller sets the budget policy; do not put user keys or billing details in agent prompts.
Limitations
The budget cap is not a strict per-token hard stop, and budget termination does not roll back tool side effects.
Pinned upstream source
- Repository
- anthropics/claude-agent-sdk-python
- File path
- examples/max_budget_usd.py
- Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Take a coding Agent change from context to verification