[ERROR] ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: Could not process image

0

I am using Bedrock, Claude 3.5 Sonnet in Tokyo region. I sometimes encounter the following error:

[ERROR] ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: Could not process image

I think this error occurs at random. Usually, my code does not generates this error. Could you tell me why this error occurs and how to fix it? Thank you in advance.

asked 4 months ago535 views
2 Answers
0

Thank you for your reply! Sorry but my case is not in the link you shared, I think. Here is the code I am using, which is using bedrock-runtime.

bedrock = boto3.client(
    'bedrock-runtime',
    region_name=os.environ.get('BEDROCK_REGION', 'ap-southeast-2'),
)

def run_completion(
    messages: list[dict[str, Any]],
    top_k: int = 1,
    max_tokens: int = 2000,
) -> tuple[str, int, int]:
    body = json.dumps(
        {
            'anthropic_version': 'bedrock-2023-05-31',
            'max_tokens': max_tokens,
            'messages': messages,
            'top_k': top_k,
        },
        ensure_ascii=False,
    )
    modelId = os.environ.get('BEDROCK_MODEL_ID', 'anthropic.claude-3-sonnet-20240229-v1:0')  # noqa
    accept = 'application/json'
    contentType = 'application/json'  # noqa

    response = bedrock.invoke_model(
        body=body,
        modelId=modelId,
        accept=accept,
        contentType=contentType,
    )
answered 4 months ago
  • This looks right for most part, do you see this error message intermittently or it's quite frequent?

  • I encounter this error roughly once in every 500 runs. What's strange is that when I rerun the same data where the error occurred, it sometimes succeeds. Therefore, I believe the issue lies on the server side.

  • In that case, I'd advise you to reach out to AWS support if you have support plan through which you can create case. Create case under technical category and they should be able to help.

0

Hi,

Thank you for posting your question.

We have covered this topic in this re:Post Knowledge Center Article How do I troubleshoot the InvokeModel API error in Amazon Bedrock?.

As mentioned in the above post, you might need to specify bedrock-runtime as a service in your API call.

Comment here if you have additional questions, happy to help.

Abhishek

profile pictureAWS
EXPERT
answered 4 months ago
profile picture
EXPERT
reviewed 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions