Skip to main content

UsageObserver

Trait UsageObserver 

Source
pub trait UsageObserver: Send + Sync {
Show 23 methods // Required methods fn response_body(&self, format: Format, body: &[u8]); fn response_line(&self, format: Format, line: &[u8]); fn request(&self, format: Format, payload: &[u8]); // Provided methods fn wants_claude_cache(&self) -> bool { ... } fn claude_cache(&self, telemetry: ClaudeCacheTelemetry) { ... } fn response_usage_line(&self, format: Format, line: &[u8]) { ... } fn plugin_executor(&self, provider: &str) { ... } fn delegated_executor(&self, executor_type: &str, model: &str) { ... } fn plugin_response_body(&self, protocol: &str, body: &[u8]) { ... } fn plugin_response_line(&self, protocol: &str, line: &[u8]) { ... } fn request_for(&self, identifier: &str, payload: &[u8]) { ... } fn upstream_model(&self, model: &str) { ... } fn response_model(&self, model: &str) { ... } fn response_model_line(&self, line: &[u8]) { ... } fn round_trip_started(&self) { ... } fn first_byte(&self) { ... } fn token_event(&self, is_token: bool) { ... } fn publish(&self) { ... } fn publish_failure(&self, status: u16, body: &str) { ... } fn publish_failure_with_usage(&self, status: u16, body: &str) { ... } fn usage_required(&self) { ... } fn discard(&self) { ... } fn upstream_stage(&self, stage: UpstreamStage) { ... }
}
Expand description

Receives the upstream payloads Go’s executors feed their usage reporter.

Required Methods§

Source

fn response_body(&self, format: Format, body: &[u8])

A whole upstream response body in format (Go Parse*Usage on the body).

Source

fn response_line(&self, format: Format, line: &[u8])

One upstream stream line in format, as received (Go feeds each scanner line to its StreamUsageBuffer and ObserveResponseModel).

Source

fn request(&self, format: Format, payload: &[u8])

The translated payload sent upstream in format (Go SetTranslatedReasoningEffort: the record’s reasoning_effort).

Provided Methods§

Source

fn wants_claude_cache(&self) -> bool

Source

fn claude_cache(&self, telemetry: ClaudeCacheTelemetry)

Content-free Claude cache facts, taken after every request rewrite.

Source

fn response_usage_line(&self, format: Format, line: &[u8])

UsageObserver::response_line for usage only (Go’s StreamUsageBuffer): the executor observes the served model on whole payloads instead.

Source

fn plugin_executor(&self, provider: &str)

The attempt runs on a plugin executor registered for provider (Go NewExecutorUsageReporter with the host’s executorAdapter): the record’s provider is that identifier and its executor type executorAdapter.

Source

fn delegated_executor(&self, executor_type: &str, model: &str)

The attempt runs on another built-in executor’s code (Go’s Vertex openapi route calls OpenAICompatExecutor.executeWithCredentials, whose reporter names its own executor_type, picking the token rule, and model).

Source

fn plugin_response_body(&self, protocol: &str, body: &[u8])

Go ParsePluginExecutorResponseUsage: a plugin executor’s whole response in its output protocol, which may be a format cliproxy-rs does not know.

Source

fn plugin_response_line(&self, protocol: &str, line: &[u8])

Go ObservePluginExecutorStreamUsage on one trimmed, non-empty line of a plugin executor’s stream in its output protocol.

Source

fn request_for(&self, identifier: &str, payload: &[u8])

UsageObserver::request where Go passes an executor identifier instead of a format (Kimi passes kimi).

Source

fn upstream_model(&self, model: &str)

Go SetUpstreamModel: the model the upstream is expected to serve, for the substitution warning only.

Source

fn response_model(&self, model: &str)

Go SetResponseModel: the served model, unless a terminal event fixed it.

Source

fn response_model_line(&self, line: &[u8])

Go ObserveResponseModel on a payload whose usage is not observed (an Antigravity payload joined from several stream lines).

Source

fn round_trip_started(&self)

Go StartResponseTTFT: the upstream request is being sent.

Source

fn first_byte(&self)

Go MarkFirstResponseByte: the first upstream body byte arrived.

Source

fn token_event(&self, is_token: bool)

Go ObserveTokenEvent: an upstream frame arrived; is_token when it carried output (Codex SSE marks TTFT at the first token, the first frame as fallback).

Source

fn publish(&self)

Go Publish/EnsurePublished now, with the usage reported so far. The first publish of an attempt wins (Go once.Do); the server’s later outcome is ignored.

Source

fn publish_failure(&self, status: u16, body: &str)

Go PublishFailure now with status (0 when the error carries none) and body; no usage. The first publish of an attempt wins.

Source

fn publish_failure_with_usage(&self, status: u16, body: &str)

Go StreamUsageBuffer.PublishFailure: UsageObserver::publish_failure with the usage reported so far.

Source

fn usage_required(&self)

The Go path has no EnsurePublished: an attempt that ends without reported usage (a reported body, or a stream line carrying usage) publishes nothing unless it fails.

Source

fn discard(&self)

Go returned before creating its usage reporter (Claude’s responses/compact 501): this attempt publishes no record at all, whatever its outcome.

Source

fn upstream_stage(&self, stage: UpstreamStage)

The attempt’s upstream exchange reached stage now. Not in Go: cliproxy-rs adds these timings and sizes to the usage record.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§