logo
Menu
Get Started with Claude 3 LLMs on Amazon Bedrock

Get Started with Claude 3 LLMs on Amazon Bedrock

Learn how to use Anthropic’s Claude 3 models, including Haiku, Sonnet, and Opus, on Amazon Bedrock now.

Banjo Obayomi
Amazon Employee
Published Mar 4, 2024
Last Modified Apr 19, 2024
Anthropic’s Claude 3 LLMs have landed on Amazon Bedrock, opening a new chapter for building generative AI applications. Claude 3, including Haiku, Sonnet, and Opus, is a family of GPT-4 level models designed for various needs. The models are multimodal from the start, making them capable of processing both text and images. You've got Haiku for speed, Sonnet for a balance of speed and intelligence, and Opus for when you need the heavy lifting of deep intelligence. Let's explore how you can start building with the Claude 3 models today.

Claude 3 benchmark
Claude 3 Benchmarks

How to create an API request with Claude 3

One of the major upgrades with Claude 3 over Claude 2 is its enhanced understanding and processing capabilities. Not only does Claude 3 provide more accurate and nuanced responses, but it also introduces a more efficient way of handling requests through the message format. This shift ensures that developers can leverage the model's capabilities more effectively, leading to faster development cycles and more intelligent applications.
Claude 3 vs Claude 3
Claude 3 accuracy
To make an API request with Claude 3, you'll need to use the message format, which is a structured way to communicate with the model. This method is straightforward and allows for more complex interactions. Below is a basic example of how you would send a request in Python:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def call_claude_sonet(prompt):

prompt_config = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
],
}
],
}

body = json.dumps(prompt_config)

modelId = "anthropic.claude-3-sonnet-20240229-v1:0"
accept = "application/json"
contentType = "application/json"

response = bedrock_runtime.invoke_model(
body=body, modelId=modelId, accept=accept, contentType=contentType
)
response_body = json.loads(response.get("body").read())

results = response_body.get("content")[0].get("text")
return results
Check out the full guide and more examples on our GitHub here.

How to process images with Claude 3

The ability for Claude 3 to process images is a game-changer. Think about automating tasks that involve user-uploaded content or quickly analyzing charts and graphs without manual input. Claude 3 can handle:
  • Photos
  • Charts and graphs
  • Technical diagrams
This opens up a ton of possibilities for creating more interactive and intelligent applications, like auto captioning.
Cat jumping into water
Cat Jumping into water
To make an image API request, you'll first need to convert your image to a base64 string, which Claude 3 can process. This step is crucial for transmitting image data over the API. Below is an example snippet to illustrate how you might send such a request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def call_claude_sonet(base64_string):

prompt_config = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4096,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": base64_string,
},
},
{"type": "text", "text": "Provide a caption for this image"},
],
}
],
}

body = json.dumps(prompt_config)

modelId = "anthropic.claude-3-sonnet-20240229-v1:0"
accept = "application/json"
contentType = "application/json"

response = bedrock_runtime.invoke_model(
body=body, modelId=modelId, accept=accept, contentType=contentType
)
response_body = json.loads(response.get("body").read())

results = response_body.get("content")[0].get("text")
return results
For detailed instructions and full code examples, visit our GitHub here.

Let's Create the Future

The arrival of Anthropic’s Claude 3 LLMs marks a pivotal moment for generative AI development on AWS. Claude’s combination of speed, intelligence, and multimodal capabilities offers a new way to start building. Get started on Amazon Bedrock with Claude 3 today and push the boundaries of what's possible.
Have an idea or question about getting started? Let's get the conversation going below. Together, we can redefine the art of possible with generative AI.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

1 Comment