2 Answers
- Newest
- Most votes
- Most comments
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 a year ago
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
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 9 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.