totalTokens property

int get totalTokens

Returns the total tokens used in the conversation

final totalTokens = chat.totalTokens;
print(totalTokens); //prints the total tokens used in the conversation

Implementation

int get totalTokens {
  if (_conversationItems.isEmpty) return 0;
  return _conversationItems.fold(
      0,
      (previousValue, element) =>
          previousValue + (element.usage?.totalTokens ?? 0));
}