Quick Start
How It Works
Configuration
| Option | Type | Description |
|---|---|---|
maxCostUsd | number | Maximum cost in USD |
maxTokens | number | Maximum output tokens |
Common Patterns
Per-Session Budget
Monitor and Alert
Batch with Shared Budget
Best Practices
Set limits before production
Set limits before production
Always configure
maxCostUsd before deploying agents to production. Without limits, a runaway loop or unexpectedly large input can result in significant API costs.Use token limits for predictability
Use token limits for predictability
maxTokens limits output length, making costs more predictable. Combine with maxCostUsd for both per-response and cumulative control.Monitor usage after each run
Monitor usage after each run
Call
agent.getUsage() after completion to track cumulative spending. Log this data to build cost forecasts over time.Match budget to task scope
Match budget to task scope
Simple Q&A tasks need less than 0.10–$0.50. Set limits to match the expected scope, not just a large safety number.
Related
Token Management
Control token usage per request
Execution
Execution settings and timeouts

