Usage
RequestUsage
Usage details for a single API request.
Source code insrc/agents/usage.py
total_tokensinstance-attribute
Total tokens (input + output) for this individual request.
input_tokens_detailsinstance-attribute
Details about the input tokens for this individual request.
Usage
Source code insrc/agents/usage.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | |
input_tokensclass-attributeinstance-attribute
Total input tokens sent, across all requests.
input_tokens_detailsclass-attributeinstance-attribute
input_tokens_details:Annotated[InputTokensDetails,BeforeValidator(_normalize_input_tokens_details),]=field(default_factory=lambda:InputTokensDetails(cached_tokens=0))Details about the input tokens, matching responses API usage details.
output_tokensclass-attributeinstance-attribute
Total output tokens received, across all requests.
output_tokens_detailsclass-attributeinstance-attribute
output_tokens_details:Annotated[OutputTokensDetails,BeforeValidator(_normalize_output_tokens_details),]=field(default_factory=lambda:OutputTokensDetails(reasoning_tokens=0))Details about the output tokens, matching responses API usage details.
total_tokensclass-attributeinstance-attribute
Total tokens sent and received, across all requests.
request_usage_entriesclass-attributeinstance-attribute
request_usage_entries:list[RequestUsage]=field(default_factory=list)List of RequestUsage entries for accurate per-request cost calculation.
Each call toadd() automatically creates an entry in this list if the added usagerepresents 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 aggregatedinput_tokens would be 330K, butrequest_usage_entries wouldpreserve the [100K, 150K, 80K] breakdown, which could be helpful for detailedcost calculation or context window management.
add
add(other:Usage)->NoneAdd 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 |