nexus-agents - v2.80.0
    Preparing search index...

    Class TokenCounter

    Universal token counter supporting multiple providers.

    Provides accurate token counting via provider APIs (Anthropic, Gemini) or local tiktoken (OpenAI), with fallback to character-based estimation.

    const counter = new TokenCounter({
    anthropicApiKey: process.env.ANTHROPIC_API_KEY,
    googleApiKey: process.env.GOOGLE_AI_API_KEY,
    });

    // Count via Anthropic API
    const result = await counter.countAnthropic(messages, 'claude-sonnet-4');

    // Count via local tiktoken
    const openaiResult = counter.countOpenAI('Hello world', 'gpt-4o');

    // Offline estimation
    const estimate = counter.estimate('Some text');

    Implements

    Index

    Constructors

    Methods