---
title: Anthropic
tags: [structured-output, caching]
integrationType: model-provider
---

[Anthropic](https://docs.anthropic.com/en/home) is an AI safety and research company focused on building reliable, interpretable, and steerable AI systems. Included in their offerings is the Claude AI family of models, which are known for their conversational abilities, careful reasoning, and capacity to follow complex instructions. The Strands Agents SDK implements an Anthropic provider, allowing users to run agents against Claude models directly.

## Installation

Anthropic is configured as an optional dependency in Strands Agents. To install, run:

<Tabs>
<Tab label="Python">

```bash
pip install 'strands-agents[anthropic]' strands-agents-tools
```
</Tab>
<Tab label="TypeScript">

```bash
npm install @strands-agents/sdk @anthropic-ai/sdk
```
</Tab>
</Tabs>

## Usage

After installing dependencies, you can import and initialize the Strands Agents' Anthropic provider as follows:

<Tabs>
<Tab label="Python">

```python
from strands import Agent
from strands.models.anthropic import AnthropicModel
from strands_tools import calculator

model = AnthropicModel(
    client_args={
        "api_key": "<KEY>",
    },
    # **model_config
    max_tokens=1028,
    model_id="claude-sonnet-4-6",
    params={
        "temperature": 0.7,
    }
)

agent = Agent(model=model, tools=[calculator])
response = agent("What is 2+2")
print(response)
```
</Tab>
<Tab label="TypeScript">

```typescript
--8<-- "user-guide/concepts/model-providers/anthropic_imports.ts:basic_usage_imports"

--8<-- "user-guide/concepts/model-providers/anthropic.ts:basic_usage"
```
</Tab>
</Tabs>

## Configuration

### Client Configuration

<Tabs>
<Tab label="Python">

The `client_args` configure the underlying Anthropic client. For a complete list of available arguments, please refer to the [Anthropic Python SDK docs](https://platform.claude.com/docs/en/api/sdks/python).
</Tab>
<Tab label="TypeScript">

The `clientConfig` configures the underlying Anthropic client. You can also pass a pre-configured `client` instance directly (see [Custom Client](#custom-client)). For a complete list of available options, please refer to the [Anthropic TypeScript SDK docs](https://platform.claude.com/docs/en/api/sdks/typescript).
</Tab>
</Tabs>

### Model Configuration

<Tabs>
<Tab label="Python">

The `model_config` configures the underlying model selected for inference. The supported configurations are:

|  Parameter | Description | Example | Options |
|------------|-------------|---------|---------|
| `max_tokens` | Maximum number of tokens to generate before stopping | `1028` | [reference](https://platform.claude.com/docs/en/api/messages/create#create.max_tokens)
| `model_id` | ID of a model to use | `claude-sonnet-4-6` | [reference](https://platform.claude.com/docs/en/api/messages/create#create.model)
| `params` | Additional pass-through parameters | `{"metadata": {"user_id": "u1"}}` | [reference](https://platform.claude.com/docs/en/api/messages/create)
</Tab>
<Tab label="TypeScript">

|  Parameter | Description | Example | Options |
|------------|-------------|---------|---------|
| `modelId` | ID of a model to use | `'claude-sonnet-4-6'` | [reference](https://platform.claude.com/docs/en/api/messages/create#create.model) |
| `maxTokens` | Maximum tokens to generate | `1028` | [reference](https://platform.claude.com/docs/en/api/messages/create#create.max_tokens) |
| `stopSequences` | Sequences that stop generation | `['END']` | [reference](https://platform.claude.com/docs/en/api/messages/create#create.stop_sequences) |
| `params` | Additional pass-through parameters | `{ metadata: { user_id: 'u1' } }` | [reference](https://platform.claude.com/docs/en/api/messages/create) |
</Tab>
</Tabs>

## Troubleshooting

<Tabs>
<Tab label="Python">

### Module Not Found

If you encounter the error `ModuleNotFoundError: No module named 'anthropic'`, this means you haven't installed the `anthropic` dependency in your environment. To fix, run `pip install 'strands-agents[anthropic]'`.
</Tab>
<Tab label="TypeScript">

### Import Errors

If you encounter import errors for `@anthropic-ai/sdk`, ensure the package is installed: `npm install @anthropic-ai/sdk`.
</Tab>
</Tabs>

## Advanced Features

### Custom Client

You can pass a pre-configured Anthropic client directly to `AnthropicModel`. You are responsible for managing the client's lifecycle.

<Tabs>
<Tab label="Python">

The Python SDK does not currently support passing a pre-configured client. Use `client_args` to configure the client at initialization.
</Tab>
<Tab label="TypeScript">

```typescript
--8<-- "user-guide/concepts/model-providers/anthropic_imports.ts:custom_client_imports"

--8<-- "user-guide/concepts/model-providers/anthropic.ts:custom_client"
```
</Tab>
</Tabs>

### Token Counting

Token counting is used by context management strategies to estimate input tokens before each model call.

<Tabs>
<Tab label="Python">

The Anthropic provider can use the native `messages.count_tokens()` API, which provides exact token counts including system prompts, messages, and tool specifications.

You can enable native token counting with:

```python
model = AnthropicModel(
    model_id="claude-sonnet-4-6",
    use_native_token_count=True,
)
```

When disabled (or if the API call fails), falls back to estimation with a character-based heuristic (characters ÷ 4 for text, characters ÷ 2 for JSON).
</Tab>
<Tab label="TypeScript">

The Anthropic provider can use the native `messages.countTokens()` API, which provides exact token counts including system prompts, messages, and tool specifications.

You can enable native token counting with:

```typescript
const model = new AnthropicModel({
  modelId: 'claude-sonnet-4-6',
  useNativeTokenCount: true,
})
```

When disabled (or if the API call fails), falls back to estimation with a character-based heuristic (characters ÷ 4 for text, characters ÷ 2 for JSON).
</Tab>
</Tabs>

## References

- [Python API](@api/python/strands.models.model)
- [Anthropic](https://platform.claude.com/docs/en/home)
