aiTokenCount function

int aiTokenCount(
  1. Object? value
)

Coerces a JSON value (provider usage counts may arrive as int or num) into a non-negative token count, returning 0 for null/unexpected types.

Implementation

int aiTokenCount(Object? value) {
  final n = value is num ? value.toInt() : 0;
  return n < 0 ? 0 : n;
}