tokens

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package tokens estimates Claude token counts using cl100k_base — the same tokenizer Claude approximates for billing.

Mirrors src/services/tokenEstimation.ts and src/utils/tokens.ts — both use a tiktoken cl100k encoder for pre-flight estimates.

The encoder is lazy-initialized on first call. If tiktoken init fails (e.g. offline first run with no cached encoding), Estimate falls back to the chars/4 heuristic so callers always get a usable number.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Estimate

func Estimate(s string) int

Estimate returns the cl100k_base token count for s. Falls back to a chars/4 estimate if the encoder isn't available.

func EstimateMany

func EstimateMany(parts []string) int

EstimateMany sums Estimate over a slice. Convenience for callers tallying over a list of message contents.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL