TokenCountEstimator

fun interface TokenCountEstimator<T>

Estimate the number of tokens in content of type T. Implementations must be thread-safe, stateless, and never throw. Always returns >= 0.

Parameterized so that estimators can operate on different content types (e.g., String for raw text, or message types for framing-aware estimation) without coupling this SPI to higher-level abstractions.

Named and shaped after Spring AI's TokenCountEstimator and Langchain4j's analogous abstractions so that users coming from those frameworks find a familiar API.

Inheritors

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun estimate(content: T): Int