pub struct UsageReport {
pub input_tokens: u64,
pub output_tokens: u64,
pub total_tokens: u64,
pub thinking_tokens: Option<u64>,
pub cache_read_tokens: Option<u64>,
pub cache_write_tokens: Option<u64>,
}Expand description
Uniform usage report emitted after each turn.
Normalizes provider-specific token counts into a simple, consistent structure that the platform uses for metering and billing.
§Example
use adk_managed::usage::UsageReport;
let report = UsageReport::new(100, 50);
assert_eq!(report.input_tokens, 100);
assert_eq!(report.output_tokens, 50);
assert_eq!(report.total_tokens, 150);Fields§
§input_tokens: u64Number of tokens in the input/prompt.
output_tokens: u64Number of tokens generated in the output/response.
total_tokens: u64Total tokens (input + output). Always equals input_tokens + output_tokens.
thinking_tokens: Option<u64>Tokens consumed by thinking/reasoning (if applicable).
cache_read_tokens: Option<u64>Tokens read from cache (if provider supports caching).
cache_write_tokens: Option<u64>Tokens written to cache (if provider supports caching).
Implementations§
Source§impl UsageReport
impl UsageReport
Sourcepub fn new(input_tokens: u64, output_tokens: u64) -> Self
pub fn new(input_tokens: u64, output_tokens: u64) -> Self
Create a new usage report with the given input and output token counts.
Total is computed automatically as input_tokens + output_tokens.
Sourcepub fn from_usage_metadata(metadata: &UsageMetadata) -> Self
pub fn from_usage_metadata(metadata: &UsageMetadata) -> Self
Create a UsageReport from adk-core’s UsageMetadata.
This is the primary conversion used by the session loop after each turn. It normalizes the provider-specific field names into the uniform format.
§Arguments
metadata- The raw usage metadata from the LLM response.
§Example
use adk_core::UsageMetadata;
use adk_managed::usage::UsageReport;
let metadata = UsageMetadata {
prompt_token_count: 150,
candidates_token_count: 75,
total_token_count: 225,
..Default::default()
};
let report = UsageReport::from_usage_metadata(&metadata);
assert_eq!(report.input_tokens, 150);
assert_eq!(report.output_tokens, 75);
assert_eq!(report.total_tokens, 225);Sourcepub fn accumulate(&mut self, other: &UsageReport)
pub fn accumulate(&mut self, other: &UsageReport)
Accumulate another report into this one (for multi-turn aggregation).
This is useful for tracking total usage across an entire session.
Trait Implementations§
Source§impl Clone for UsageReport
impl Clone for UsageReport
Source§fn clone(&self) -> UsageReport
fn clone(&self) -> UsageReport
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UsageReport
impl Debug for UsageReport
Source§impl Default for UsageReport
impl Default for UsageReport
Source§fn default() -> UsageReport
fn default() -> UsageReport
Source§impl<'de> Deserialize<'de> for UsageReport
impl<'de> Deserialize<'de> for UsageReport
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for UsageReport
Source§impl PartialEq for UsageReport
impl PartialEq for UsageReport
Source§impl Serialize for UsageReport
impl Serialize for UsageReport
impl StructuralPartialEq for UsageReport
Auto Trait Implementations§
impl Freeze for UsageReport
impl RefUnwindSafe for UsageReport
impl Send for UsageReport
impl Sync for UsageReport
impl Unpin for UsageReport
impl UnsafeUnpin for UsageReport
impl UnwindSafe for UsageReport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.