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 Answer
0
Accepted Answer

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
EXPERT
answered 14 days ago
profile pictureAWS
EXPERT
reviewed 14 days ago
  • 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.

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

Relevant content