tokencount

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateInputTokens

func EstimateInputTokens(req *CountTokensRequest) int

EstimateInputTokens estimates input tokens for a request

func EstimateOutputTokens

func EstimateOutputTokens(text string) int

EstimateOutputTokens estimates tokens for output text

Types

type CountTokensRequest

type CountTokensRequest struct {
	Model    string         `json:"model" binding:"required"`
	Messages []MessageParam `json:"messages" binding:"required"`
	System   any            `json:"system,omitempty"`
	Tools    []Tool         `json:"tools,omitempty"`
}

CountTokensRequest matches Anthropic's official API specification

type CountTokensResponse

type CountTokensResponse struct {
	InputTokens int `json:"input_tokens"`
}

type MessageParam

type MessageParam struct {
	Role    string `json:"role" binding:"required"`
	Content any    `json:"content" binding:"required"`
}

type Tool

type Tool struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	InputSchema any    `json:"input_schema,omitempty"`
}

Jump to

Keyboard shortcuts

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