Skip to main content
Agents can enforce spending limits to prevent runaway costs — set a max budget and the agent stops automatically.

Quick Start

1

Simple Usage

2

With Configuration

3

With Token Limits


How It Works


Configuration


Common Patterns

Per-Session Budget

Monitor and Alert

Batch with Shared Budget


Best Practices

Always configure maxCostUsd before deploying agents to production. Without limits, a runaway loop or unexpectedly large input can result in significant API costs.
maxTokens limits output length, making costs more predictable. Combine with maxCostUsd for both per-response and cumulative control.
Call agent.getUsage() after completion to track cumulative spending. Log this data to build cost forecasts over time.
Simple Q&A tasks need less than 0.01.Detailedresearchtasksmayneed0.01. Detailed research tasks may need 0.10–$0.50. Set limits to match the expected scope, not just a large safety number.

Token Management

Control token usage per request

Execution

Execution settings and timeouts