# How should I set turn and spend limits for a Claude Agent SDK run?

Exam: CCAR-F — Claude Certified Architect - Foundations (CCAR-F)
Knowledge domain: Agentic Architecture & Orchestration
Updated: 2026-11-25T09:22:55.685627+00:00
HTML: https://learningpathx.com/faq/CCAR-F/ccarf-agent-sdk-turn-and-budget-limits.html

## Also asked as

- What should I budget for when setting max turns and max budget in the Claude Agent SDK?
- How does the Claude Agent SDK report when a turn or budget cap is reached?

Set `max_turns` in Python or `maxTurns` in TypeScript to bound the number of model turns. Count each pass through the loop, including the final text-only turn. For example, an investigation that needs three tool-calling turns and one final answer needs at least four turns. Set `max_budget_usd` or `maxBudgetUsd` to cap the run against estimated spend. The check happens after responses arrive, so provide headroom for spend above the threshold.

Handle `error_max_turns` and `error_max_budget_usd` as incomplete outcomes. Keep any verified evidence, record what remains, and decide whether to ask for input or run a narrower task. In a single-shot query the reported error result can be followed by an iterator exception. With Claude Code v2.1.217 or later providing the SDK runtime, the documented budget enforcement includes subagent spend and stops remaining background subagents at the cap.

Use a separate elapsed-time limit if the caller has a deadline, restrict tools independently, and verify the outcome against the task’s acceptance criteria. An SDK limit ends work on its own terms. The host decides what to do with any partial work.

[Agent SDK turns, budget, and stop handling](https://code.claude.com/docs/en/agent-sdk/agent-loop#turns-and-budget)

Source: [Choosing Single-Shot, Workflow, and Agentic Claude Architectures](https://learningpathx.com/news/choosing-single-shot-workflow-and-agentic-claude-architectures.html)
