token

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package token estimates LLM token counts from byte content using a characters-per-token heuristic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(content []byte) int

EstimateTokens provides a rough token count estimate for content.

Uses a simple heuristic of ~4 characters per token for English text. This is a conservative estimate for Claude/GPT-style tokenizers that tends to slightly overestimate, which is safer for budgeting.

Parameters:

  • content: Byte slice to estimate tokens for

Returns:

  • int: Estimated token count (0 for empty content)

func EstimateTokensString

func EstimateTokensString(s string) int

EstimateTokensString estimates tokens for a string.

Convenience wrapper around EstimateTokens for string input.

Parameters:

  • s: String to estimate tokens for

Returns:

  • int: Estimated token count

Types

This section is empty.

Jump to

Keyboard shortcuts

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