agentskit.js

ProviderTokenCounterOptions

Auto-generated API reference for ProviderTokenCounterOptions.

Interface: ProviderTokenCounterOptions

Defined in: token-counter.ts:125

Options for creating a provider-specific token counter.

#Properties

#name

name: string

Defined in: token-counter.ts:143

Human-readable name for this counter.


#perMessageOverhead?

optional perMessageOverhead?: number

Defined in: token-counter.ts:145

Per-message overhead in tokens. Defaults to 4.


#tokenize

tokenize: (text, model?) => readonly unknown[] | Promise<readonly unknown[]>

Defined in: token-counter.ts:141

The tokenize function from a provider-specific tokenizer library. Must return an array of token ids (or any array whose .length represents the token count).

#Parameters

text

string

model?

string

#Returns

readonly unknown[] | Promise<readonly unknown[]>

#Example

import { encoding_for_model } from 'tiktoken'
const enc = encoding_for_model('gpt-4o')
const counter = createProviderCounter({
  name: 'tiktoken',
  tokenize: (text) => [...enc.encode(text)],
})

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page