pub struct UsageEvent {
pub timestamp: SystemTime,
pub request_id: String,
pub principal: Option<String>,
pub model: String,
pub provider: String,
pub endpoint: &'static str,
pub usage: Usage,
pub duration_ms: u64,
pub status: u16,
pub error: Option<String>,
}Expand description
Per-request event emitted after a request completes. Embedders
subscribe to the AppState::usage_events broadcast channel to
observe live traffic without scraping the Prometheus endpoint.
Fields§
§timestamp: SystemTime§request_id: String§principal: Option<String>§model: String§provider: String§endpoint: &'static strLogical endpoint: "chat.completions", "embeddings",
"images.generations", "audio.speech", "audio.transcriptions".
usage: UsageFull canonical usage with all axes (input, cache_read, cache_write,
output, reasoning, audio, per-call tools). Embeds the same type that
drives billing in crabllm_core::ModelInfo::cost, so subscribers
see exactly what was charged for.
duration_ms: u64§status: u16The wire HTTP status the client observed, or 0 when a
streaming chat response sent 200 OK headers and then broke
mid-stream. 0 is a sentinel meaning “not a real HTTP
response” — consumers branching on status alone can
distinguish a clean 200 from a failed stream without having
to inspect Self::error. For non-streaming requests
status is always the real HTTP code the client saw.
error: Option<String>Some(msg) if the request failed. Set alongside status == 0
for mid-stream streaming failures; set alongside a real error
status (4xx/5xx) for pre-stream and non-streaming failures.
Trait Implementations§
Source§impl Clone for UsageEvent
impl Clone for UsageEvent
Source§fn clone(&self) -> UsageEvent
fn clone(&self) -> UsageEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more