---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/llm/anthropic_messages/adapter/classes/AnthropicMessagesAdapter.md
description: >-
  Opinionated cross-environment LLM adapter for the Anthropic Messages wire
  shape.
---

# Class: AnthropicMessagesAdapter

Defined in: [src/batteries/llm/anthropic\_messages/adapter.ts:469](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/adapter.ts#L469)

Opinionated cross-environment LLM adapter for the Anthropic Messages wire shape.

## Remarks

Construction validates options eagerly via [validateOptions](../../validation/functions/validateOptions.md) and throws
[@nhtio/adk/batteries/llm/anthropic\_messages!E\_INVALID\_ANTHROPIC\_MESSAGES\_OPTIONS](../../exceptions/variables/E_INVALID_ANTHROPIC_MESSAGES_OPTIONS.md) on
failure. The returned instance is reusable: call [AnthropicMessagesAdapter.executor](#executor) once
per `DispatchRunner` configuration to obtain a [@nhtio/adk!DispatchExecutorFn](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md) bound to
the baseline plus optional executor-scope overrides. Per-iteration overrides live on
`ctx.stash.anthropicMessages` and take highest precedence; `headers`, `helpers`, and `retry`
merge key-by-key across all three layers, every other field is replaced wholesale at the
highest layer that sets it. Node-first: browser is explicitly not a target — an Anthropic API
key in a browser bundle is unacceptably exposed.

## Constructors

### Constructor

```ts
new AnthropicMessagesAdapter(options: unknown): AnthropicMessagesAdapter;
```

Defined in: [src/batteries/llm/anthropic\_messages/adapter.ts:480](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/adapter.ts#L480)

#### Parameters

| Parameter | Type      | Description                                                                                                                  |
| --------- | --------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `options` | `unknown` | Constructor-baseline options. Re-validated on every iteration after per-dispatch and per-iteration overrides are layered in. |

#### Returns

`AnthropicMessagesAdapter`

#### Throws

[@nhtio/adk/batteries/llm/anthropic\_messages!E\_INVALID\_ANTHROPIC\_MESSAGES\_OPTIONS](../../exceptions/variables/E_INVALID_ANTHROPIC_MESSAGES_OPTIONS.md) when `options` does not satisfy `anthropicMessagesOptionsSchema`.

## Properties

| Property                                    | Modifier   | Type                  | Description                                               | Defined in                                                                                                                                                      |
| ------------------------------------------- | ---------- | --------------------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|  `STASH_KEY` | `readonly` | `"anthropicMessages"` | Customary key for per-iteration overrides on `ctx.stash`. | [src/batteries/llm/anthropic\_messages/adapter.ts:471](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/adapter.ts#L471) |

## Methods

### countTokens()

```ts
countTokens(input:
  | AnthropicMessagesCountTokensRequestInput
  | AnthropicMessagesCountTokensInput, overrides?: Partial<AnthropicMessagesAdapterOptions>): Promise<{
  inputTokens: number;
  raw: unknown;
}>;
```

Defined in: [src/batteries/llm/anthropic\_messages/adapter.ts:1536](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/adapter.ts#L1536)

Counts the input tokens a request would consume, without generating.

Uses Anthropic's dedicated count-tokens surface (a distinct parameter shape from a create
request, and one that takes no `maxTokens`), and returns a named field plus the raw upstream
body rather than leaking the vendor type through this battery's public API.

`input` accepts either a dispatch context — whose prompt is assembled with the same helpers the
executor uses — or a pre-built Anthropic-shaped request. Option precedence, revalidation,
timeout ownership, and error translation all match [AnthropicMessagesAdapter.executor](#executor).

#### Parameters

| Parameter    | Type                                                                                                                                                                                                                               |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input`      | | [`AnthropicMessagesCountTokensRequestInput`](../../count_tokens/type-aliases/AnthropicMessagesCountTokensRequestInput.md) | [`AnthropicMessagesCountTokensInput`](../../types/interfaces/AnthropicMessagesCountTokensInput.md) |
| `overrides?` | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`AnthropicMessagesAdapterOptions`](../../types/interfaces/AnthropicMessagesAdapterOptions.md)>                                         |

#### Returns

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

***

### executor()

```ts
executor(overrides?: Partial<AnthropicMessagesAdapterOptions>): DispatchExecutorFn;
```

Defined in: [src/batteries/llm/anthropic\_messages/adapter.ts:491](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/adapter.ts#L491)

Returns a [@nhtio/adk!DispatchExecutorFn](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md) bound to this adapter's baseline plus optional
executor-scope overrides.

#### Parameters

| Parameter    | Type                                                                                                                                                                                       | Description                                                                                                           |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
| `overrides?` | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`AnthropicMessagesAdapterOptions`](../../types/interfaces/AnthropicMessagesAdapterOptions.md)> | Optional executor-scope overrides. Higher precedence than the baseline, lower precedence than `ctx.stash[STASH_KEY]`. |

#### Returns

[`DispatchExecutorFn`](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md)

***

### isAnthropicMessagesAdapter()

```ts
static isAnthropicMessagesAdapter(value: unknown): value is AnthropicMessagesAdapter;
```

Defined in: [src/batteries/llm/anthropic\_messages/adapter.ts:1546](https://github.com/NHTIO/ADK/blob/v1.20260726.0/src/src/batteries/llm/anthropic_messages/adapter.ts#L1546)

Returns `true` when `value` is an AnthropicMessagesAdapter instance.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `value`   | `unknown` |

#### Returns

`value is AnthropicMessagesAdapter`
