Skip to content

Token count fields don't distinguish estimated vs actual values #1

Description

@piotrekno1

Problem

TextInputMeta.tokenCount and GenerationOutputMeta.tokensOut are emitted as plain integers in inference events regardless of whether they came from a real tokenizer or from a heuristic approximation (wordCount / 0.75 for input, charCount / 4 for output).

For non-English text, code-heavy prompts, or models with non-GPT tokenizers (Gemma, LLaMA, Phi), the approximation error is frequently 2–3x. The backend and dashboard have no way to tell which numbers to trust.

Proposed fix

Add a companion boolean field to both TextInputMeta and GenerationOutputMeta:

  • tokenCountEstimated: Booleantrue when the approximation heuristic was used, false when a real tokenizer was provided by the caller

Wire format addition (backwards-compatible — field absent on old clients):

"token_count": 42,
"token_count_estimated": true

This lets the backend suppress or annotate estimated values in analytics, and lets the dashboard surface a nudge to provide a real tokenizer.

No breaking changes required

The field is additive. Old clients omitting it can be treated as estimated by the backend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions