pub struct TokenUsageRecord {Show 20 fields
pub ts: String,
pub session_id: String,
pub model: String,
pub provider: String,
pub message_count: usize,
pub cache_creation_input_tokens: u64,
pub cache_read_input_tokens: u64,
pub input_tokens: u64,
pub output_tokens: u64,
pub thinking_tokens: u64,
pub system_tokens: u32,
pub summary_tokens: u32,
pub window_tokens: u32,
pub total_tokens: u32,
pub max_context_tokens: u32,
pub budget_limit: u32,
pub prompt_cached_tool_outputs: usize,
pub prompt_cached_tool_tokens_saved: u32,
pub truncation_occurred: bool,
pub segments_removed: usize,
}Expand description
One per-LLM-call usage record. Flattened for line-oriented analysis (jq / DuckDB / pandas over the JSONL).
Fields§
§ts: StringRFC3339 wall-clock timestamp captured when the call completed.
session_id: String§model: String§provider: String§message_count: usizeConversation length (message count) at emit time — a monotonic-ish ordinal to correlate records with conversation growth.
cache_creation_input_tokens: u64§cache_read_input_tokens: u64§input_tokens: u64Non-cached “fresh” input tokens (server-reported), disjoint from the two
cache counts. The precise prompt size is
input_tokens + cache_read + cache_creation, and the exact cache-hit
ratio is cache_read / that_sum.
output_tokens: u64§thinking_tokens: u64§system_tokens: u32§summary_tokens: u32§window_tokens: u32§total_tokens: u32§max_context_tokens: u32§budget_limit: u32§prompt_cached_tool_outputs: usize§prompt_cached_tool_tokens_saved: u32§truncation_occurred: bool§segments_removed: usizeImplementations§
Source§impl TokenUsageRecord
impl TokenUsageRecord
Sourcepub fn new(
ts: String,
session_id: &str,
model: &str,
provider: &str,
message_count: usize,
usage: Option<&TokenBudgetUsage>,
cache_creation_input_tokens: u64,
cache_read_input_tokens: u64,
input_tokens: u64,
output_tokens: u64,
thinking_tokens: u64,
) -> Self
pub fn new( ts: String, session_id: &str, model: &str, provider: &str, message_count: usize, usage: Option<&TokenBudgetUsage>, cache_creation_input_tokens: u64, cache_read_input_tokens: u64, input_tokens: u64, output_tokens: u64, thinking_tokens: u64, ) -> Self
Build a record from the prompt-side budget snapshot (usage) and the
server-side stream stats. The cache-creation count lives only on the
stream output — it is not part of TokenBudgetUsage — so it is passed
in explicitly.
Sourcepub fn to_json_line(&self) -> Result<String, Error>
pub fn to_json_line(&self) -> Result<String, Error>
Serialize to a single-line JSON string (no trailing newline; the storage layer frames the line).
Trait Implementations§
Source§impl Clone for TokenUsageRecord
impl Clone for TokenUsageRecord
Source§fn clone(&self) -> TokenUsageRecord
fn clone(&self) -> TokenUsageRecord
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more