pub struct UsageRecord {
pub id: Uuid,
pub session_id: Uuid,
pub message_id: Uuid,
pub provider: String,
pub model: String,
pub input_tokens: u64,
pub output_tokens: u64,
pub total_tokens: u64,
pub created_at: DateTime<Utc>,
}Expand description
Detailed token usage record for a single provider interaction.
Tracks per-request token consumption broken down by provider, model, session, and message for cost accounting and analytics.
Fields§
§id: UuidUnique record identifier.
session_id: UuidSession this usage belongs to.
message_id: UuidMessage that produced this usage.
provider: StringProvider that served the request.
model: StringModel that served the request.
input_tokens: u64Number of input (prompt) tokens consumed.
output_tokens: u64Number of output (completion) tokens consumed.
total_tokens: u64Total token count.
created_at: DateTime<Utc>When the usage was recorded.
Implementations§
Source§impl UsageRecord
impl UsageRecord
Sourcepub fn new(
session_id: Uuid,
message_id: Uuid,
provider: impl Into<String>,
model: impl Into<String>,
usage: TokenUsage,
) -> Self
pub fn new( session_id: Uuid, message_id: Uuid, provider: impl Into<String>, model: impl Into<String>, usage: TokenUsage, ) -> Self
Creates a usage record from a provider response with a generated UUIDv7 ID and current timestamp.
The token counts are extracted from the given TokenUsage struct.
Trait Implementations§
Source§impl Clone for UsageRecord
impl Clone for UsageRecord
Source§fn clone(&self) -> UsageRecord
fn clone(&self) -> UsageRecord
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UsageRecord
impl Debug for UsageRecord
Source§impl<'de> Deserialize<'de> for UsageRecord
impl<'de> Deserialize<'de> for UsageRecord
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for UsageRecord
impl PartialEq for UsageRecord
Source§fn eq(&self, other: &UsageRecord) -> bool
fn eq(&self, other: &UsageRecord) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for UsageRecord
impl Serialize for UsageRecord
impl StructuralPartialEq for UsageRecord
Auto Trait Implementations§
impl Freeze for UsageRecord
impl RefUnwindSafe for UsageRecord
impl Send for UsageRecord
impl Sync for UsageRecord
impl Unpin for UsageRecord
impl UnsafeUnpin for UsageRecord
impl UnwindSafe for UsageRecord
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