ModelNotAvailableException
aws_bedrock.exceptions.ModelNotAvailableException
Stack trace
aws_bedrock.exceptions.ModelNotAvailableException: The requested model is not available in the current AWS region.
at aws_bedrock.client.invoke_model (client.py:123)
at app.main (main.py:45) Why it happens
AWS Bedrock models are region-specific and not all models are deployed in every AWS region. If your client is configured to use a region where the model is not available, the service throws this exception. This prevents calls to unsupported endpoints and ensures compliance with regional deployments.
Detection
Check the AWS region configured in your Bedrock client before making model calls. Validate model availability via AWS console or Bedrock API before runtime to avoid this error.
Causes & fixes
The AWS Bedrock client is configured to a region where the requested model is not deployed.
Change the AWS region in your client configuration to a region where the model is available, such as us-east-1 or us-west-2.
The model name specified is incorrect or deprecated in the current region.
Verify the exact model name supported in your region via AWS Bedrock documentation or console and update your code accordingly.
Using default AWS region environment variables that do not match the model's deployment region.
Explicitly set the AWS_REGION environment variable or client region parameter to the correct region supporting the model.
Code: broken vs fixed
import os
from aws_bedrock import BedrockClient
client = BedrockClient(region_name=os.environ.get('AWS_REGION'))
response = client.invoke_model(model_id='anthropic.claude-v1', input='Hello') # This line raises ModelNotAvailableException import os
from aws_bedrock import BedrockClient
# Set region explicitly to a supported region for the model
os.environ['AWS_REGION'] = 'us-east-1'
client = BedrockClient(region_name=os.environ.get('AWS_REGION'))
response = client.invoke_model(model_id='anthropic.claude-v1', input='Hello') # Fixed: region set correctly
print(response) Workaround
Catch ModelNotAvailableException and fallback to a different region or model dynamically by querying available models via the Bedrock API before invocation.
Prevention
Implement region validation logic in your deployment pipeline or startup code to confirm model availability in the configured region, and use AWS Bedrock's model listing APIs to dynamically select supported models per region.