approximateCounter
Auto-generated API reference for approximateCounter.
Variable: approximateCounter
constapproximateCounter:TokenCounter
Defined in: token-counter.ts:44
A fast, zero-dependency approximate token counter.
Uses the chars / 4 heuristic plus a small per-message overhead
to account for chat framing tokens.
Good enough for budget checks and context-window guards. For exact
counts, use a provider-specific counter (e.g. createTiktokenCounter).
#Example
import { approximateCounter } from '@agentskit/observability'
const tokens = approximateCounter.count(messages)
if (tokens > 120_000) trimOldMessages(messages)