Source code for ffai.core.usage

# Copyright (c) 2025 Antonio Quinonez / Far Finer LLC
# SPDX-License-Identifier: MIT
# Contact: antquinonez@farfiner.com

"""Token usage tracking for AI client responses."""

from __future__ import annotations

from dataclasses import dataclass


[docs] @dataclass class TokenUsage: """Token usage from an AI model API response. Attributes: input_tokens: Number of tokens in the prompt. output_tokens: Number of tokens in the completion. total_tokens: Total tokens (input + output). """ input_tokens: int = 0 output_tokens: int = 0 total_tokens: int = 0 def __add__(self, other: TokenUsage) -> TokenUsage: return TokenUsage( input_tokens=self.input_tokens + other.input_tokens, output_tokens=self.output_tokens + other.output_tokens, total_tokens=self.total_tokens + other.total_tokens, )