How do I access Anthropic Claude models on Amazon Bedrock?

2 minute read
0

I want to access Anthropic Claude models on Amazon Bedrock, but I don’t know how to.

Short description

Because the process to request access is different from other foundation models, you might not be able to access Anthropic Claude models on Amazon Bedrock. To get access to Anthropic Claude models, submit a use case details form. After you're granted access, save your changes.

Resolution

Request access to Anthropic Claude models on Amazon Bedrock

To access Anthropic Claude models on Amazon Bedrock, complete the following steps:

  1. Open the Amazon Bedrock console.
  2. In the navigation pane, choose Model access.
  3. Choose Submit use case details, and then enter the information. Then, choose Submit.
  4. Wait for the Submit use case details button to become grayed out.
  5. Select Anthropic, and then choose Save changes.

Test your access to Anthropic

To test if you can access the Anthropic Claude models, use the Text or Chat feature on the Amazon Bedrock console. Or, you can use the API call.

In the following example, an Amazon SageMaker role is configured for Amazon Bedrock. To test the Amazon Bedrock runtime setup, run the following command:

import boto3
import json
bedrock = boto3.client(service_name='bedrock-runtime')

body = json.dumps({
    "prompt": "\n\n

Human:explain black holes to 8th graders\n\n

Assistant:",
    "max_tokens_to_sample": 300,
    "temperature": 0.1,
    "top_p": 0.9,
})

modelId = 'anthropic.claude-v2'
accept = 'application/json'
contentType = 'application/json'

response = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)

response_body = json.loads(response.get('body').read())
# text
print(response_body.get('completion'))

To test the Amazon Bedrock setup, run the following command:

import boto3
bedrock = boto3.client(service_name='bedrock')

bedrock.get_foundation_model(modelIdentifier='anthropic.claude-v2')
AWS OFFICIAL
AWS OFFICIALUpdated 10 days ago