AccessDeniedException: An error occurred (AccessDeniedException) when calling the InvokeModelWithResponseStream operation: You don't have access to the model with the specified model ID.

0

I've been calling Claude via bedrock through the following steps and commands:

!ada credentials update --account=xxxxxxxxxxx --role=IibsAdminAccess-DO-NOT-DELETE --provider=conduit --once

import boto3
print(boto3.__version__)
import json

#Create the connection to Bedrock
bedrock = boto3.client(
    service_name='bedrock',
    region_name='us-west-2', 
    
)

bedrock_runtime = boto3.client(
    service_name='bedrock-runtime',
    region_name='us-west-2', 
    
)
def run_bedrock (prompt_data):
    body = {"prompt": "Human: " + prompt_data + " \\nAssistant:",
        "max_tokens_to_sample": 300, 
        "temperature": 0,
        "stop_sequences": ["\\n\\nHuman:"],
        "anthropic_version": "bedrock-2023-05-31"}

    body = json.dumps(body) # Encode body as JSON string

    modelId = 'anthropic.claude-v2' 
    accept = 'application/json'
    contentType = 'application/json'

    response = bedrock_runtime.invoke_model_with_response_stream(body=body.encode('utf-8'), # Encode to bytes
                                 modelId=modelId, 
                                 accept=accept, 
                                 contentType=contentType)
    r = []
    for event in response['body']:
        data = json.loads(event['chunk']['bytes'])
        r.append(data['completion'])
    return r    

It has been working fine so far. Today, I changed the AWS account number in the ada command. Now, when I try to get Claude response on an input, I'm facing the following error. AccessDeniedException: An error occurred (AccessDeniedException) when calling the InvokeModelWithResponseStream operation: You don't have access to the model with the specified model ID.

It only happens when I use that specific AWS account to call bedrock. Does anyone know why?

已提問 1 個月前檢視次數 298 次
1 個回答
1
已接受的答案

Hello.

Is the model enabled in the "us-west-2" region of the target AWS account?
In the case of claude, it cannot be used unless model access is enabled.
https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html

profile picture
專家
已回答 1 個月前
profile picture
專家
已審閱 5 天前
profile pictureAWS
專家
已審閱 1 個月前
  • Thanks for your response. How can I check if the model is enabled in the "us-west-2" region of the target AWS account? If not, how can I enable it?

  • To check, on AWS Console: Bedrock > Model Access and then request access if you don't have it. Usually granted instantly

  • You can do it by following the steps mentioned by @Didier_Durand. Here are the steps from the AWS documentation. https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html#model-access-add
    You can check the actual screen by accessing the Bedrock console and clicking "Model access" at the bottom left of the screen. a

  • If the model is not enabled, click "Manage model access" and check the model you want to enable. a
    a
    Once checked, click "Request model access" to enable it. a

  • The issue is now resolved. The issue was that I requested access for the models in us-east-1 region but calling those from us-west-2 region. It worked after the region-mismatch was fixed. Thanks for all your help.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南