---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/llm/anthropic_messages/count_tokens/functions/countAnthropicMessagesTokens.md
---

# 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](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/count_tokens.ts#L541)

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

## Parameters

| Parameter    | Type                                                                                                                                                                                                               | Description                                                              |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
| `baseline`   | [`AnthropicMessagesAdapterOptions`](../../types/interfaces/AnthropicMessagesAdapterOptions.md)                                                                                                                     | Constructor-baseline adapter options.                                    |
| `input`      | | [`AnthropicMessagesCountTokensRequestInput`](../type-aliases/AnthropicMessagesCountTokensRequestInput.md) | [`AnthropicMessagesCountTokensInput`](../../types/interfaces/AnthropicMessagesCountTokensInput.md) | Either a `DispatchContext` or a pre-built Anthropic-shaped input object. |
| `overrides?` | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`AnthropicMessagesAdapterOptions`](../../types/interfaces/AnthropicMessagesAdapterOptions.md)>                         | Optional executor-scope overrides with lower precedence than stash.      |
| `deps?`      | [`AnthropicMessagesCountTokensDeps`](../interfaces/AnthropicMessagesCountTokensDeps.md)                                                                                                                            | Optional helper dependencies, including the structured log channel.      |

## Returns

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

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