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§
Sourcefn response_body(&self, format: Format, body: &[u8])
fn response_body(&self, format: Format, body: &[u8])
A whole upstream response body in format (Go Parse*Usage on the body).
Sourcefn response_line(&self, format: Format, line: &[u8])
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).
Provided Methods§
fn wants_claude_cache(&self) -> bool
Sourcefn claude_cache(&self, telemetry: ClaudeCacheTelemetry)
fn claude_cache(&self, telemetry: ClaudeCacheTelemetry)
Content-free Claude cache facts, taken after every request rewrite.
Sourcefn response_usage_line(&self, format: Format, line: &[u8])
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.
Sourcefn plugin_executor(&self, provider: &str)
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.
Sourcefn delegated_executor(&self, executor_type: &str, model: &str)
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).
Sourcefn plugin_response_body(&self, protocol: &str, body: &[u8])
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.
Sourcefn plugin_response_line(&self, protocol: &str, line: &[u8])
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.
Sourcefn request_for(&self, identifier: &str, payload: &[u8])
fn request_for(&self, identifier: &str, payload: &[u8])
UsageObserver::request where Go passes an executor identifier instead of a
format (Kimi passes kimi).
Sourcefn upstream_model(&self, model: &str)
fn upstream_model(&self, model: &str)
Go SetUpstreamModel: the model the upstream is expected to serve, for the
substitution warning only.
Sourcefn response_model(&self, model: &str)
fn response_model(&self, model: &str)
Go SetResponseModel: the served model, unless a terminal event fixed it.
Sourcefn response_model_line(&self, line: &[u8])
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).
Sourcefn round_trip_started(&self)
fn round_trip_started(&self)
Go StartResponseTTFT: the upstream request is being sent.
Sourcefn first_byte(&self)
fn first_byte(&self)
Go MarkFirstResponseByte: the first upstream body byte arrived.
Sourcefn token_event(&self, is_token: bool)
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).
Sourcefn publish(&self)
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.
Sourcefn publish_failure(&self, status: u16, body: &str)
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.
Sourcefn publish_failure_with_usage(&self, status: u16, body: &str)
fn publish_failure_with_usage(&self, status: u16, body: &str)
Go StreamUsageBuffer.PublishFailure: UsageObserver::publish_failure with the
usage reported so far.
Sourcefn usage_required(&self)
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.
Sourcefn discard(&self)
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.
Sourcefn upstream_stage(&self, stage: UpstreamStage)
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".