Skip to content
1 min read · 104 words

Function: countAnthropicMessagesTokens()

ts
function countAnthropicMessagesTokens(
  baseline: AnthropicMessagesAdapterOptions,
  input:
    | AnthropicMessagesCountTokensRequestInput
    | AnthropicMessagesCountTokensInput,
  overrides?: Partial<AnthropicMessagesAdapterOptions>,
  deps?: AnthropicMessagesCountTokensDeps,
): Promise<{
  inputTokens: number;
  raw: unknown;
}>;

Defined in: src/batteries/llm/anthropic_messages/count_tokens.ts:541

Counts tokens using constructor-baseline options plus executor-style overrides and stash.

Parameters

ParameterTypeDescription
baselineAnthropicMessagesAdapterOptionsConstructor-baseline adapter options.
input| AnthropicMessagesCountTokensRequestInput | AnthropicMessagesCountTokensInputEither a DispatchContext or a pre-built Anthropic-shaped input object.
overrides?Partial<AnthropicMessagesAdapterOptions>Optional executor-scope overrides with lower precedence than stash.
deps?AnthropicMessagesCountTokensDepsOptional helper dependencies, including the structured log channel.

Returns

Promise<{ inputTokens: number; raw: unknown; }>

The named token-count field plus the raw SDK response.