An optional capability a provider MAY implement to count the tokens a request would consume before sending it.
Useful for pre-flight budget checks, context-window guards, and cost
estimates. Like EmbeddingProvider this is an opt-in mixin interface:
check support at runtime with provider is TokenCounter. Providers without
a token-count endpoint simply do not implement it.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
countTokens(
AiConversation conversation, {List< ToolDefinition> tools, AiRequestOptions? options}) → Future<int> -
Returns the number of tokens
conversation(plus anytoolsandoptions) would occupy in a generation request. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited