Skip to main content

Module token

Module token 

Source
Expand description

Token estimation and usage tracking for agent sessions.

This module provides approximate token counting for messages and cumulative usage tracking across turns. Token estimation uses character-based heuristics:

  • ASCII text: ~4 characters per token
  • Non-ASCII text (CJK, etc.): ~2 characters per token

The request admission layer adds an explicit safety margin for text. Image parts use a conservative declared-size policy because dimensions are not always available at this boundary.

Structsยง

ModelPricing
Pricing information for a language model, expressed as cost per 1,000 tokens.
TokenEstimator
Estimates token counts for messages and tracks cumulative usage across turns.