pub struct TokenUsageTracker { /* private fields */ }Expand description
Thread-safe token usage tracker. Tracks usage by session, model, and total.
Implementations§
Source§impl TokenUsageTracker
impl TokenUsageTracker
Sourcepub async fn increment(
&self,
session_id: i64,
model: &str,
input_tokens: i64,
output_tokens: i64,
)
pub async fn increment( &self, session_id: i64, model: &str, input_tokens: i64, output_tokens: i64, )
Increment token usage for a session and model.
Sourcepub async fn get_session_usage(&self, session_id: i64) -> Option<TokenMeter>
pub async fn get_session_usage(&self, session_id: i64) -> Option<TokenMeter>
Get token usage for a specific session. Returns None if the session has no recorded usage.
Sourcepub async fn get_model_usage(&self, model: &str) -> Option<TokenMeter>
pub async fn get_model_usage(&self, model: &str) -> Option<TokenMeter>
Get token usage for a specific model. Returns None if the model has no recorded usage.
Sourcepub async fn get_total_usage(&self) -> TokenMeter
pub async fn get_total_usage(&self) -> TokenMeter
Get total token usage across all sessions and models.
Sourcepub async fn get_all_session_usage(&self) -> HashMap<i64, TokenMeter>
pub async fn get_all_session_usage(&self) -> HashMap<i64, TokenMeter>
Get all session usage as a map.
Sourcepub async fn get_all_model_usage(&self) -> HashMap<String, TokenMeter>
pub async fn get_all_model_usage(&self) -> HashMap<String, TokenMeter>
Get all model usage as a map.
Sourcepub async fn remove_session(&self, session_id: i64)
pub async fn remove_session(&self, session_id: i64)
Remove usage tracking for a session (e.g., when session is deleted).
Sourcepub async fn session_count(&self) -> usize
pub async fn session_count(&self) -> usize
Get the number of tracked sessions.
Sourcepub async fn model_count(&self) -> usize
pub async fn model_count(&self) -> usize
Get the number of tracked models.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TokenUsageTracker
impl !RefUnwindSafe for TokenUsageTracker
impl Send for TokenUsageTracker
impl Sync for TokenUsageTracker
impl Unpin for TokenUsageTracker
impl !UnwindSafe for TokenUsageTracker
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more