pub struct LlmCompletionMetadata {
pub total_tokens: Option<u32>,
pub prompt_tokens: Option<u32>,
pub completion_tokens: Option<u32>,
pub cache_read_tokens: Option<u32>,
pub cache_creation_tokens: Option<u32>,
pub provider_cost_usd: Option<f64>,
pub model: Option<String>,
pub finish_reason: Option<String>,
pub retry_metadata: Option<RetryMetadata>,
pub response_id: Option<String>,
pub phase: Option<String>,
}Expand description
Metadata about LLM completion
Contains token usage and completion information from the LLM response.
Token buckets are disjoint by convention (see the TokenUsage event): drivers
normalize provider wire formats at the boundary so prompt_tokens carries
only non-cached input, with cache_read_tokens / cache_creation_tokens
additive on top. Inclusive providers (OpenAI Responses / Chat Completions,
Gemini) subtract their cached count from the reported prompt total via
disjoint_prompt_tokens; Anthropic / Bedrock already report disjoint
buckets and pass values through unchanged.
Fields§
§total_tokens: Option<u32>Total tokens used (non-cached prompt + cache read/creation + completion)
prompt_tokens: Option<u32>Non-cached prompt tokens (cached reads are excluded; see struct docs)
completion_tokens: Option<u32>Completion tokens
cache_read_tokens: Option<u32>Tokens read from cache (reduces cost), disjoint from prompt_tokens
cache_creation_tokens: Option<u32>Tokens written to cache (Anthropic-specific), disjoint from prompt_tokens
provider_cost_usd: Option<f64>Authoritative cost of this generation in USD, when the provider reports
it inline (e.g. OpenRouter’s usage.cost). None for providers that do
not return a cost.
model: Option<String>Model used
finish_reason: Option<String>Finish reason
retry_metadata: Option<RetryMetadata>Retry metadata (present if rate limit retries occurred)
response_id: Option<String>Provider’s response ID (e.g., OpenAI response ID from response.completed).
Used for previous_response_id chaining and OTel tracing.
phase: Option<String>Execution phase from the provider’s response (e.g., “commentary”, “final_answer”). When present, this value should be preserved on the assistant message and sent back as-is in subsequent requests. Only set by providers with native phase support.
Trait Implementations§
Source§impl Clone for LlmCompletionMetadata
impl Clone for LlmCompletionMetadata
Source§fn clone(&self) -> LlmCompletionMetadata
fn clone(&self) -> LlmCompletionMetadata
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LlmCompletionMetadata
impl Debug for LlmCompletionMetadata
Source§impl Default for LlmCompletionMetadata
impl Default for LlmCompletionMetadata
Source§fn default() -> LlmCompletionMetadata
fn default() -> LlmCompletionMetadata
Auto Trait Implementations§
impl Freeze for LlmCompletionMetadata
impl RefUnwindSafe for LlmCompletionMetadata
impl Send for LlmCompletionMetadata
impl Sync for LlmCompletionMetadata
impl Unpin for LlmCompletionMetadata
impl UnsafeUnpin for LlmCompletionMetadata
impl UnwindSafe for LlmCompletionMetadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request