What this thread does
Do first: Pass usage_limits=UsageLimits(request_limit=3, output_tokens_limit=10) to an already configured agent run; handle UsageLimitExceeded.
Short answer
The documented examples cap model turns at 3 and output tokens at 10. Request limits are checked before the next agent-loop step; token limits normally follow a billed response.
What to do
| Control | Accepted value / default | Effect |
|---|---|---|
usage_limits | UsageLimits(...) on run, run_sync, run_stream | Supplies run limits |
request_limit | int or None; default 50 | Caps responses committed to run history |
input_tokens_limit | int or None; default None | Cumulative input tokens |
output_tokens_limit | int or None; default None | Cumulative output tokens |
total_tokens_limit | int or None; default None | Input plus output tokens |
per_request_input_tokens_limit | int or None; default None | Context size per request, including cached input |
count_tokens_before_request | bool; default False, set True for preflight counting | Enforces input limits before sending; supported by Anthropic, Google, Bedrock Converse, OpenAI Responses |
tool_calls_limit | int or None; default None | Successful tool executions; checked before execution |
cost_limit | Decimal or None; default None | USD cap; normally checked after a response |
None disables an individual limit. Catch UsageLimitExceeded; diagnostic fragments include Exceeded the output_tokens_limit of 10 and The next request would exceed the request_limit of 3. The output example reports output_tokens=32, showing an overshoot.
For a conversation-wide allowance across resumed runs, carry earlier usage with usage= or conversation=. Tools can read ctx.usage_limits and ctx.usage.
Limits and open questions
A request cap counts agent turns, excluding fallback attempts, provider continuation requests and transport retries. Their tokens and cost can still count. A token or cost boundary can be crossed by a billed response; that response is retained as state='interrupted' unless a hook rejected it with ModelRetry. Streaming also checks tokens as chunks arrive. Preflight counting adds overhead. Parallel tool calls that would cross the tool limit are all withheld. Missing usage can produce UsageLimitUnavailableWarning; reported totals are then lower bounds. These pages give no release date for this API.
Not for: LiteLLM proxy limits across multiple virtual keys.
Sources
Checked
2026-11-17; read Agents; UsageLimits API; Agents (input URL); no command was run.
Started from a post by @pydantic, packaged by the editor. Original post