Guide

How to put a budget on an OpenAI Agents SDK agent

The OpenAI Agents SDK can stop a run after a number of turns. It cannot stop a run after a number of dollars.

Short answer

Runner.run takes max_turns, which raises MaxTurnsExceeded when a run uses too many turns, but the OpenAI Agents SDK has no dollar limit. To cap spend, use run hooks that add up the cost of each model call and refuse the next one when the run's budget is used.

For a short task with a small model, a turn limit is enough. For agents with long contexts, big models or many tools, turns and cost drift apart fast. Here is what the SDK gives you and how to add a real budget.

What the SDK gives you

Runner.run takes max_turns. If a run goes past it, the SDK raises MaxTurnsExceeded. Passing max_turns=None turns the limit off.

from agents import Agent, Runner
from agents.exceptions import MaxTurnsExceeded

agent = Agent(name="Support", instructions="...", tools=[lookup_order, issue_refund])

try:
    result = await Runner.run(agent, "Where is order 1042?", max_turns=8)
except MaxTurnsExceeded:
    print("Stopped: too many turns")

The SDK also has input, output and tool guardrails, which are checks you write, and tools can be marked as needing human approval. These are useful for checking content. None of them counts money.

Why a turn limit is not a budget

  • Turns get more expensive as the run goes on, because each turn sends the whole conversation so far.
  • One turn can be one tool call or many. The bill depends on what happens inside each turn.
  • Handoffs move work between agents, which may use different models at different prices.

Adding a budget

The SDK has run hooks that fire around each model call and tool call. A budget check belongs there: add up the cost of each model call from the usage it reports, and refuse the next call once the run's budget is used. Keep the prices for each model up to date.

One gap to know about. An agent used through Agent.as_tool() runs as a separate run, so hooks on the outer run do not see its calls. If you nest agents this way, put limits on the inner run too, or use a gateway in front of the model, which sees every call.

Doing it with SteerPlane

SteerPlane's Agents SDK integration does this with the SDK's own run hooks, with prices for over 100 models, plus a step limit, a time limit and deny rules on tool names. Install it with pip install steerplane:

from steerplane.integrations.openai_agents import SteerPlaneAgentHooks

hooks = SteerPlaneAgentHooks(
    agent_name="support_agent",
    model="gpt-4o-mini",
    max_cost_usd=0.25,
    max_steps=40,
    max_runtime_sec=120,
    denied_actions=["delete_*", "drop_*"],
)

result = await hooks.run(agent, "Where is order 1042?")   # raises the SteerPlane error if a limit stops it

If you want to call the Runner yourself, pass the hooks in:

hooks.start()
try:
    result = await Runner.run(agent, "Where is order 1042?", hooks=hooks.run_hooks)
finally:
    hooks.finish()

Each model call and each tool call counts as one step, and once the run reaches a limit the next call is refused. Called this way, a stop before a tool call reaches you wrapped in the SDK's UserError, with the SteerPlane error as its cause; hooks.run raises the SteerPlane error directly. Every run shows up in the dashboard with its steps, cost and why it stopped.

We tested both ways on 24 November 2026 with version 1.1.5 and gpt-4o-mini, using a tool that always fails and an agent told to keep retrying. With max_cost_usd=0.0003, both runs were ended with a cost limit error. In the same test, max_turns=3 raised MaxTurnsExceeded as documented.

Loop detection is off by default here, because it matches on tool names and would stop a healthy run that calls the same tool over a list. Setup steps are on the setup page, and how this compares with the SDK's own guardrails is on the comparison page.

A checklist for Agents SDK agents

  • max_turns set on every run.
  • A dollar budget per run, checked before each model call.
  • Approval on tools that pay, send or delete.
  • Limits on nested agents used as tools, not just the outer run.
  • A test run built to overspend, to prove the budget stops it.

Questions people ask

Does the OpenAI Agents SDK have a cost limit?

No. It can cap the number of turns with max_turns, and you can write guardrails, but there is no built-in setting that stops a run at a dollar amount.

What happens when max_turns is exceeded?

The SDK raises MaxTurnsExceeded, from agents.exceptions. Pass max_turns=None to turn the limit off.

Do run hooks see agents used as tools?

No. An agent used through Agent.as_tool() runs as a separate run, so hooks on the outer run do not count its calls. A gateway in front of the model sees every call.

Keep reading
Design partners

Shipping agents? Let's talk.

Our first 10 design partners get every paid feature free, plus direct help setting up.