TokenUsage (models/tokens.rs)

chronikl · src/models/tokens.rs · rust · Apache-2.0
ai

Tracks LLM token usage for billing and analytics.

// Source: https://github.com/nsrosenqvist/chronikl | License: Apache-2.0 | Copyright 2026 Niklas Rosenqvist
// Provided via justclaw.it.com; keep this notice with the code.
//! Token-usage accounting for LLM calls.

use std::ops::AddAssign;

use serde::{Deserialize, Serialize};

/// Token counts produced by a single LLM call.
///
/// `cached_input_tokens` is non-zero only for providers that report it
/// (Anthropic with explicit caching, OpenAI's automatic prefix caching,
/// Gemini 2.5+, DeepSeek, …). For providers that don't, it stays at 0.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct TokenUsage {
    pub input_tokens: u64,
    pub output_tokens: u64,
    pub cached_input_tokens: u64,
    pub total_tokens: u64,
}

impl TokenUsage {
    pub fn 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key