Skip to main content

MaxTokens

Control the maximum number of tokens an agent or agentic function can generate.
Parameters
int | None
The maximum number of output tokens generated over all rounds of inference in a single invocation. Defaults to None meaning unlimited.
int | None
The maximum number of output tokens generated in a single round of inference in a single invocation. Defaults to None meaning unlimited.
int | None
The maximum number of rounds of inference in a single invocation. Defaults to None meaning unlimited.

ResponseUsage

Token usage statistics returned by all usage-reporting methods. This is ResponseUsage from openai.types.responses, which provides richer detail including cached and reasoning token breakdowns.
Key Fields
int
The number of input tokens consumed by the model.
int
The number of output tokens generated by the model.
int
The number of input tokens that were served from cache.
int
The number of tokens used for internal reasoning / chain-of-thought.
Example

total_usage

Get the total token usage of an agent or agentic function across all invocations.
Parameters
AgenticFunction | Agent | Callable[..., Any]
The agent, agentic function, or decorated callable to query.
ResponseUsage
The token usage across all invocations of the agent or agentic function.

last_usage

Get the token usage of an agent or agentic function for the last invocation.
Parameters
AgenticFunction | Agent | Callable[..., Any]
The agent, agentic function, or decorated callable to query.
ResponseUsage
The token usage of the last invocation of the agent or agentic function.