pub struct UsageEvent {
pub timestamp: SystemTime,
pub request_id: String,
pub key_name: Option<String>,
pub model: String,
pub provider: String,
pub endpoint: &'static str,
pub tokens_in: u32,
pub tokens_out: u32,
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§key_name: Option<String>§model: String§provider: String§endpoint: &'static strLogical endpoint: "chat.completions", "embeddings",
"images.generations", "audio.speech", "audio.transcriptions".
tokens_in: u32Prompt / input tokens. For embeddings this is the input token count; for image / audio endpoints it’s 0.
tokens_out: u32Completion / output tokens. 0 for endpoints that don’t generate tokens (embeddings, images, audio).
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more