Calling Claude through Bedrock slightly differs from how you would call Claude when using Anthropic’s client SDK’s. This guide will walk you through the process of completing an API call to Claude on Bedrock in either Python or TypeScript.

Note that this guide assumes you have already signed up for an AWS account and configured programmatic access.

Install and configure the AWS CLI

  1. Install a version of the AWS CLI at or newer than version 2.13.23
  2. Configure your AWS credentials using the AWS configure command (see Configure the AWS CLI) or find your credentials by navigating to “Command line or programmatic access” within your AWS dashboard and following the directions in the popup modal.
  3. Verify that your credentials are working:
aws sts get-caller-identity  

Install an SDK for accessing Bedrock

Anthropic’s client SDKs support Bedrock. You can also use an AWS SDK like boto3 directly.

pip install -U "anthropic[bedrock]"

Accessing Bedrock

Subscribe to Anthropic models

Go to the AWS Console > Bedrock > Model Access and request access to Anthropic models. Note that Anthropic model availability varies by region. See AWS documentation for latest information.

API model names

ModelBedrock API model name
Claude 3 Haikuanthropic.claude-3-haiku-20240307-v1:0
Claude 3 Sonnetanthropic.claude-3-sonnet-20240229-v1:0
Claude 3 Opusanthropic.claude-3-opus-20240229-v1:0

List available models

The following examples show how to print a list of all the Claude models available through Bedrock:

aws bedrock list-foundation-models --region=us-west-2 --by-provider anthropic --query "modelSummaries[*].modelId"

Making requests

The following examples shows how to generate text from Claude 3 Sonnet on Bedrock:

from anthropic import AnthropicBedrock

client = AnthropicBedrock(
    # Authenticate by either providing the keys below or use the default AWS credential providers, such as
    # using ~/.aws/credentials or the "AWS_SECRET_ACCESS_KEY" and "AWS_ACCESS_KEY_ID" environment variables.
    aws_access_key="<access key>",
    aws_secret_key="<secret key>",
    # Temporary credentials can be used with aws_session_token.
    #
    # aws_region changes the aws region to which the request is made. By default, we read AWS_REGION,
    # and if that's not present, we default to us-east-1. Note that we do not read ~/.aws/config for the region.

message = client.messages.create(
    messages=[{"role": "user", "content": "Hello, world"}]

See our client SDKs for more details, and the official Bedrock docs here.