Skip to main content

tt_shared/
usage.rs

1//! Token usage and cost accounting. Token counts come from provider responses —
2//! we never estimate locally for billing.
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Usage {
8    pub prompt_tokens: u64,
9    pub completion_tokens: u64,
10    pub total_tokens: u64,
11
12    /// Cached input tokens (Anthropic cache_read_input_tokens, OpenAI cached_tokens).
13    /// Always populated by the adapter; 0 when no cache hit.
14    #[serde(default)]
15    pub cached_tokens: u64,
16
17    /// Anthropic-specific: tokens written to cache on this call.
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub cache_creation_input_tokens: Option<u64>,
20}