Usage
RequestUsage
Usage details for a single API request.
Source code in src/agents/usage.py
total_tokens
instance-attribute
Total tokens (input + output) for this individual request.
input_tokens_details
instance-attribute
Details about the input tokens for this individual request.
Usage
Source code in src/agents/usage.py
input_tokens
class-attribute
instance-attribute
Total input tokens sent, across all requests.
input_tokens_details
class-attribute
instance-attribute
input_tokens_details: InputTokensDetails = field(
default_factory=lambda: InputTokensDetails(
cached_tokens=0
)
)
Details about the input tokens, matching responses API usage details.
output_tokens
class-attribute
instance-attribute
Total output tokens received, across all requests.
output_tokens_details
class-attribute
instance-attribute
output_tokens_details: OutputTokensDetails = field(
default_factory=lambda: OutputTokensDetails(
reasoning_tokens=0
)
)
Details about the output tokens, matching responses API usage details.
total_tokens
class-attribute
instance-attribute
Total tokens sent and received, across all requests.
request_usage_entries
class-attribute
instance-attribute
request_usage_entries: list[RequestUsage] = field(
default_factory=list
)
List of RequestUsage entries for accurate per-request cost calculation.
Each call to add() automatically creates an entry in this list if the added usage
represents a new request (i.e., has non-zero tokens).
Example
For a run that makes 3 API calls with 100K, 150K, and 80K input tokens each,
the aggregated input_tokens would be 330K, but request_usage_entries would
preserve the [100K, 150K, 80K] breakdown, which could be helpful for detailed
cost calculation or context window management.
add
add(other: Usage) -> None
Add another Usage object to this one, aggregating all fields.
This method automatically preserves request_usage_entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Usage
|
The Usage object to add to this one. |
required |