- Newest
- Most votes
- Most comments
To pass attachments using the Claude 3.5 API via Amazon Bedrock, you need to make a few adjustments to your code. Here are the key changes:
- The "type" for image content should be "image", not "image".
- The key for specifying the image format should be "media_type", not "mime_type".
- Make sure you're using the correct model ID for Claude 3.5.
Here's the corrected version of the relevant part of your code:
messages_content.append({ "type": "image", "source": { "type": "base64", "media_type": mime_type, "data": base64.b64encode(file_content).decode('utf-8') } }) request_body = { "anthropic_version": "bedrock-2023-05-31", "max_tokens": 10000, "messages": [{ "role": "user", "content": messages_content }] } response = self.bedrock_client.invoke_model( modelId="anthropic.claude-3-sonnet-20240229-v1:0", body=json.dumps(request_body) )
Make sure you're using the correct model ID for Claude 3.5. As of the latest information available, the model ID for Claude 3 Sonnet is "anthropic.claude-3-sonnet-20240229-v1:0".
Also, ensure that you're converting your image to a base64 string correctly. The API expects the image data to be in this format.
Remember to handle potential errors, such as unsupported file types or oversized attachments. Claude 3.5 supports various image formats, but there may be limitations on file sizes or types.
After making these adjustments, your code should be able to successfully pass attachments to the Claude 3.5 API via Amazon Bedrock.
Sources
Community | Get Started with Claude 3 LLMs on Amazon Bedrock
Community | Sending images to Claude 3 using Amazon Bedrock.
answered 2 years ago
application/pdf is supported as a correct media_type on Anthropic model. Refer to the documentation here : https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages.html#api-inference-examples-claude-messages-code-examples
media_type – (required) The type of the image. You can specify the following image formats.
- image/jpeg
- image/png
- image/webp
- image/gif
answered 2 years ago
Relevant content
asked 5 months ago
- AWS OFFICIALUpdated 22 days ago

I tried that and I get provisioned througput error, with the model ID anthropic.claude-3-sonnet-20240229-v1:0. I can use the 3.5 API with ondemand provisioning.
RuntimeError: Bedrock API call failed: An error occurred (ValidationException) when calling the InvokeModel operation: Invocation of model ID anthropic.claude-3-sonnet-20240229-v1:0 with on-demand throughput isn’t supported. Retry your request with the ID or ARN of an inference profile that contains this model.