MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / get_usage

Method get_usage

crates/opencode-session/src/session.rs:527–542  ·  view source on GitHub ↗

Aggregate usage across all assistant messages in the session

(&self)

Source from the content-addressed store, hash-verified

525
526 /// Aggregate usage across all assistant messages in the session
527 pub fn get_usage(&self) -> SessionUsage {
528 let mut usage = SessionUsage::default();
529 for msg in &self.messages {
530 if matches!(msg.role, MessageRole::Assistant) {
531 if let Some(ref msg_usage) = msg.usage {
532 usage.input_tokens += msg_usage.input_tokens;
533 usage.output_tokens += msg_usage.output_tokens;
534 usage.reasoning_tokens += msg_usage.reasoning_tokens;
535 usage.cache_write_tokens += msg_usage.cache_write_tokens;
536 usage.cache_read_tokens += msg_usage.cache_read_tokens;
537 usage.total_cost += msg_usage.total_cost;
538 }
539 }
540 }
541 usage
542 }
543
544 /// Share the session (set share URL)
545 pub fn share_session(&mut self, url: impl Into<String>) {

Callers 2

test_get_usage_emptyFunction · 0.80

Calls

no outgoing calls

Tested by 2

test_get_usage_emptyFunction · 0.64