- Newest
- Most votes
- Most comments
Hello.
I'm not sure since I haven't seen the full code, but are you using the Text Completions API?
Amazon Bedrock's Text Completions API cannot use Claude-3-Sonnet etc. as of March 2024.
Only the following models are compatible.
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-text-completion.html
- Anthropic Claude Instant v1.2
- Anthropic Claude v2
- Anthropic Claude v2.1
For Messages API, you can use Claude-3-Sonnet etc. as shown below.
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages.html
import boto3
import json
def lambda_handler(event, context):
bedrock = boto3.client('bedrock-runtime', region_name = "us-east-1")
body = json.dumps(
{
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1000,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text":"Hello My name is Riku"
}
]
}
]
}
)
modelId = 'anthropic.claude-3-sonnet-20240229-v1:0'
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())
answer = response_body["content"][0]["text"]
print(answer)
Hi Here a response using AWS Bedrock in 2024.
Basically I had the same error message, what I did was:
- Follow the next documentation [1], here are some simple examples of what you can do using different program lenguages.
- Double check the Anthopic_version in the body request, I was using a different one that the supported [2]
- Double check if you are using a supported model id. You can see the available ones in this link [3]
- Double check if you have access to the model in the AWS Bedrock console. Here the steps to configure the model access [4]
Additional, a good way to try this [1] examples really quick is using Amazon Lambda, just modify the AWS IAM role of the lambda and add the less privilege in order to use Amazon bedrock.
Hope this information is usefull. Best regards
Edgar Hernández ITera's AWS Data and Analytics Manger (MX)
[1] Invoke Anthropic Claude models on Amazon Bedrock using the Invoke Model API. https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_InvokeModel_AnthropicClaude_section.html
[2] Anthropic_version used "anthropic_version": "bedrock-2023-05-31"
[3] Amazon Bedrock base model IDs (on-demand throughput) https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns
[4] Add model access https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html
Relevant content
- asked 7 months ago
- asked 6 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 6 months ago