# How to Use the Anthropic SDK with AWS Bedrock: A Complete Guide

> Learn how to use the Anthropic SDK with AWS Bedrock. This guide details seamless integration with specialized clients for simplified authentication and region management.

- Repository: [Anthropic/anthropic-sdk-python](https://github.com/anthropics/anthropic-sdk-python)
- Tags: how-to-guide
- Published: 2026-02-23

---

**The Anthropic SDK provides specialized `AnthropicBedrock` and `AsyncAnthropicBedrock` clients that automatically handle AWS Signature V4 authentication, region resolution, and endpoint transformation while exposing the same API surface as the standard Anthropic client.**

Using the Anthropic SDK with AWS Bedrock allows you to invoke Claude models through your existing AWS infrastructure without managing separate API keys. The SDK abstracts Bedrock-specific implementation details—such as request signing and event-stream decoding—while maintaining full compatibility with the Messages API, streaming, and tool use capabilities.

## Understanding the Anthropic Bedrock Client Architecture

The Bedrock integration is implemented as a specialized client library that extends the core SDK functionality with AWS-specific authentication and transport logic.

### Core Client Classes

The primary entry points are `AnthropicBedrock` for synchronous operations and `AsyncAnthropicBedrock` for asynchronous workloads. Both classes are defined in [`src/anthropic/lib/bedrock/_client.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/lib/bedrock/_client.py) and inherit from `BaseBedrockClient`, which itself extends the SDK's `BaseClient`.

According to the source code, these clients override critical methods including `_prepare_options` for endpoint rewriting and `_prepare_request` for authentication header injection.

### Authentication and Request Signing

Unlike the standard Anthropic client that uses API key authentication, Bedrock requires AWS Signature Version 4 signing. The SDK handles this transparently through the `get_auth_headers` helper in [`src/anthropic/lib/bedrock/_auth.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/lib/bedrock/_auth.py).

When you initiate a request, the client's `_prepare_request` method automatically calls this helper to generate the required `Authorization` and `X-Amz-Date` headers using your configured AWS credentials.

## Setting Up Region and Credentials

The SDK provides intelligent defaults for AWS region configuration while respecting explicit overrides.

### Automatic Region Inference

If you do not specify an `aws_region` parameter when instantiating the client, the SDK invokes the `_infer_region()` method (lines 70-90 in [`_client.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/_client.py)). This method checks the following sources in order:

1. The `AWS_REGION` environment variable
2. The `AWS_DEFAULT_REGION` environment variable
3. The region configured in the current boto3 session
4. Falls back to `us-east-1` if no region is found

```python
from anthropic import AnthropicBedrock

# Region will be inferred from environment or boto3 configuration

client = AnthropicBedrock()

```

### AWS Credential Chain

The SDK relies on the standard boto3 credential resolution chain. You do not need to pass explicit credentials to the Anthropic SDK. Instead, ensure your environment has one of the following:

- IAM role attached to an EC2 instance or Lambda function
- AWS credentials in `~/.aws/credentials`
- Environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`

## Making API Calls with AnthropicBedrock

The client exposes the same `messages.create()` and `messages.stream()` interfaces as the standard Anthropic API, with Bedrock-specific model ID formatting.

### Basic Synchronous Requests

When calling `messages.create()`, the SDK automatically transforms the request path from `/v1/messages` to the Bedrock-specific `/model/{model}/invoke` format.

```python
from anthropic import AnthropicBedrock

client = AnthropicBedrock()

response = client.messages.create(
    model="anthropic.claude-sonnet-4-5-20250929-v1:0",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain quantum computing in simple terms"}],
)

print(response.content[0].text)

```

### Streaming Responses

For streaming, the SDK uses `AWSEventStreamDecoder` (defined in [`src/anthropic/lib/bedrock/_stream_decoder.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/lib/bedrock/_stream_decoder.py)) to parse Bedrock's event-stream format into the standard SDK `Stream` abstraction.

```python
from anthropic import AnthropicBedrock

client = AnthropicBedrock()

with client.messages.stream(
    model="anthropic.claude-sonnet-4-5-20250929-v1:0",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about Python"}],
) as stream:
    # Real-time token output

    for token in stream.text_stream:
        print(token, end="", flush=True)
    
    # Access the complete message after streaming finishes

    final_message = stream.get_final_message()
    print(f"\n\nFull response: {final_message.model_dump_json(indent=2)}")

```

### Asynchronous Usage

The `AsyncAnthropicBedrock` class provides identical functionality for async/await patterns.

```python
import asyncio
from anthropic import AsyncAnthropicBedrock

async def main():
    client = AsyncAnthropicBedrock()
    
    response = await client.messages.create(
        model="anthropic.claude-sonnet-4-5-20250929-v1:0",
        max_tokens=512,
        messages=[{"role": "user", "content": "What is the capital of France?"}],
    )
    
    print(response.content[0].text)

asyncio.run(main())

```

## Key Differences from Standard Anthropic API

When using the Anthropic SDK with AWS Bedrock, be aware of these implementation constraints defined in [`src/anthropic/lib/bedrock/_client.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/lib/bedrock/_client.py) (lines 61-66):

- **Batch API is not supported**: The Bedrock client does not implement batch processing capabilities available in the standard API.
- **Token counting is not supported**: The `count_tokens` method is disabled for Bedrock deployments.

Additionally, model IDs must use Bedrock's ARN format (e.g., `anthropic.claude-sonnet-4-5-20250929-v1:0`) rather than the standard Anthropic model names (e.g., `claude-3-5-sonnet-20241022`).

## Summary

- The **Anthropic SDK** provides `AnthropicBedrock` and `AsyncAnthropicBedrock` clients specifically designed for AWS Bedrock integration.
- **Authentication** is handled automatically via AWS Signature V4 using your standard boto3 credential chain—no Anthropic API key required.
- **Region resolution** follows a fallback chain: explicit parameter → `AWS_REGION` env var → boto3 session → `us-east-1`.
- The SDK **translates API paths** automatically, converting standard `/v1/messages` endpoints to Bedrock's `/model/{model}/invoke` format.
- **Streaming** is fully supported through `AWSEventStreamDecoder`, which parses Bedrock's event-stream protocol into standard SDK stream objects.
- **Batch API and token counting** are explicitly disabled for Bedrock clients.

## Frequently Asked Questions

### How do I configure AWS credentials for the Anthropic Bedrock client?

The Anthropic Bedrock client uses the standard boto3 credential resolution chain. You do not pass credentials directly to the client. Instead, configure your environment with either an IAM role (for EC2/Lambda), AWS credentials in `~/.aws/credentials`, or the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. The `get_auth_headers` function in [`src/anthropic/lib/bedrock/_auth.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/lib/bedrock/_auth.py) automatically signs requests using these credentials.

### What AWS region does the Anthropic SDK use by default for Bedrock?

If you do not specify the `aws_region` parameter, the SDK calls `_infer_region()` which checks the `AWS_REGION` environment variable first, then `AWS_DEFAULT_REGION`, then attempts to read the region from the current boto3 session. If none of these sources provide a region, the client defaults to `us-east-1`. You can always override this behavior by passing `aws_region="us-west-2"` when instantiating `AnthropicBedrock`.

### Why does the Bedrock client not support batch processing or token counting?

According to the source code in [`src/anthropic/lib/bedrock/_client.py`](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/lib/bedrock/_client.py) (lines 61-66), these features are explicitly disabled because AWS Bedrock does not expose equivalent endpoints for batch inference or token counting through its InvokeModel API. The Bedrock client raises `NotImplementedError` with messages stating "Batch API is not supported" and "Token counting is not supported" if you attempt to use these methods. For batch workloads, you must implement your own queuing mechanism or use Bedrock's native batch inference jobs outside the Anthropic SDK.