Skip to main content

UsageEntry

Struct UsageEntry 

Source
pub struct UsageEntry {
Show 14 fields pub session_id: String, pub timestamp_ms: u64, pub model: String, pub input_tokens: u64, pub output_tokens: u64, pub cache_read_tokens: u64, pub cache_write_tokens: u64, pub cache_write_1h_tokens: u64, pub web_search_requests: u64, pub speed: Option<String>, pub tool_uses: Vec<String>, pub text_chars: u32, pub activity: Activity, pub entrypoint: Option<String>,
}
Expand description

Flat row representing a single completed assistant turn.

One entry per unique message.id. Claude Code writes multiple JSONL entries per assistant message as the stream progresses (typically 2-3), all sharing the same id and final usage numbers — dedup keeps only the first occurrence.

Token field semantics (inherited from Anthropic’s API):

  • input_tokens: fresh tokens in this turn’s prompt that were NOT served from cache. Small when conversation is reused, large on cache misses.
  • cache_read_tokens: tokens served from the prompt cache (cheap).
  • cache_write_tokens: tokens written into the prompt cache (~25% premium).
  • output_tokens: tokens generated by the model.

“Total context sent” for a turn = input + cache_read + cache_write.

Fields§

§session_id: String§timestamp_ms: u64

Unix epoch ms from the JSONL timestamp field. 0 if unparseable.

§model: String§input_tokens: u64§output_tokens: u64§cache_read_tokens: u64§cache_write_tokens: u64

Total cache-write (creation) tokens for this turn: max(legacy flat cache_creation_input_tokens, ephemeral_5m + ephemeral_1h). The 1-hour subset is broken out separately in cache_write_1h_tokens for pricing; this total still drives cache-hit % and token displays.

§cache_write_1h_tokens: u64

The 1-hour-TTL portion of cache_write_tokens (from usage.cache_creation.ephemeral_1h_input_tokens). Billed at 2× input vs the 5-minute tier’s 1.25×. The 5-minute portion is the remainder.

§web_search_requests: u64

Anthropic web-search server-tool requests this turn (usage.server_tool_use.web_search_requests). Billed flat at $0.01 each.

§speed: Option<String>

usage.speed: "standard" or "fast". Some("fast") applies the fast-mode cost multiplier (see fast_multiplier_for_model). None on rows that predate the field.

§tool_uses: Vec<String>

Names of tools this turn invoked (from tool_use content blocks). Empty for pure-text turns. Duplicates preserved when the model called the same tool multiple times in one turn.

§text_chars: u32

Sum of text content block character counts for this turn. Zero means a silent tool-only turn; non-zero means the model said something.

§activity: Activity

Classified activity category (Coding, Debugging, Exploration, …). See the crate::activity module for the decision tree.

§entrypoint: Option<String>

JSONL entrypoint field captured from the first row of each message id. "cli" = interactive Claude Code session. "sdk-cli" = headless claude -p spawn (any Agent SDK consumer lands here). None for legacy rows that predate the field. Useful for distinguishing interactive vs. headless usage; also load-bearing once Anthropic splits Agent SDK billing from interactive plans (announced June 2026).

Trait Implementations§

Source§

impl Clone for UsageEntry

Source§

fn clone(&self) -> UsageEntry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UsageEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UsageEntry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for UsageEntry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more