pub struct Usage {
pub input_tokens: u64,
pub cached_input_tokens: u64,
pub cache_write_tokens: u64,
pub output_tokens: u64,
}Expand description
Token counts of one call, normalised across providers.
input_tokens is every prompt token, including the ones served from or
written to the cache; cached_input_tokens and cache_write_tokens say how
many of them get the cache prices instead of the normal input price.
Fields§
§input_tokens: u64All prompt tokens, cached or not.
cached_input_tokens: u64Prompt tokens read from the provider’s cache (part of input_tokens).
cache_write_tokens: u64Prompt tokens written to the provider’s cache (part of input_tokens).
output_tokens: u64Completion tokens, including any reasoning or “thinking” tokens.
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn fresh_input_tokens(&self) -> u64
pub fn fresh_input_tokens(&self) -> u64
Prompt tokens billed at the normal input price.
Sourcepub fn from_json(text: &str) -> Result<Self, BudgetError>
pub fn from_json(text: &str) -> Result<Self, BudgetError>
Parse a provider response body, or just its usage object, from JSON text.
§Errors
BudgetError::InvalidConfig if the text is not JSON or has no
recognisable usage block.
Sourcepub fn from_value(v: &Value) -> Result<Self, BudgetError>
pub fn from_value(v: &Value) -> Result<Self, BudgetError>
Same as from_json for an already parsed value.
§Errors
BudgetError::InvalidConfig if there is no recognisable usage block.
Trait Implementations§
impl Copy for Usage
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Usage
Source§impl From<&CompletionUsage> for Usage
Available on crate feature async-openai only.
impl From<&CompletionUsage> for Usage
async-openai only.Source§fn from(u: &CompletionUsage) -> Self
fn from(u: &CompletionUsage) -> Self
Source§impl JsonSchema for Usage
Available on crate feature schemars only.
impl JsonSchema for Usage
schemars only.Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more