I'm attempting to use AWSSDK.Extensions.Bedrock.MEAI
to create a console app that interacts with Amazon Bedrock, specifically using Claude 3 Haiku.
This code worked fine with other models, but for some reason I keep getting this error with Claude 3 Haiku:
Amazon.BedrockRuntime.Model.ValidationException: The provided model identifier is invalid.
---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)
at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
--- End of inner exception stack trace ---
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.BaseAuthResolverHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.BedrockRuntime.BedrockChatClient.GetStreamingResponseAsync(IList`1 chatMessages, ChatOptions options, CancellationToken cancellationToken)+MoveNext()
at Amazon.BedrockRuntime.BedrockChatClient.GetStreamingResponseAsync(IList`1 chatMessages, ChatOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Program.<Main>$(String[] args) in /Users/minnbran/GitHub/Bedrock-MEAI-Sample/src/AiChatClient.Console/Program.cs:line 10
at Program.<Main>$(String[] args) in /Users/minnbran/GitHub/Bedrock-MEAI-Sample/src/AiChatClient.Console/Program.cs:line 10
at Program.<Main>(String[] args)
Code
using AiChatClient.Common;
using AiChatClient.Console;
using Amazon;
using Amazon.BedrockRuntime;
var bedrockService = new BedrockService(
new AmazonBedrockRuntimeClient(AwsCredentials.AccessKeyId, AwsCredentials.SecretAccessKey, RegionEndpoint.USWest1),
"anthropic.claude-3-haiku-20240307-v1:0");
await foreach (var response in bedrockService.GetStreamingResponseAsync("Is this working?", new(), CancellationToken.None))
{
Console.Write(response.Text);
}
I'm attempting to use AWSSDK.Extensions.Bedrock.MEAI
to create a console app that interacts with Amazon Bedrock, specifically using Claude 3 Haiku.
This code worked fine with other models, but for some reason I keep getting this error with Claude 3 Haiku:
Amazon.BedrockRuntime.Model.ValidationException: The provided model identifier is invalid.
---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)
at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
--- End of inner exception stack trace ---
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.BaseAuthResolverHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.BedrockRuntime.BedrockChatClient.GetStreamingResponseAsync(IList`1 chatMessages, ChatOptions options, CancellationToken cancellationToken)+MoveNext()
at Amazon.BedrockRuntime.BedrockChatClient.GetStreamingResponseAsync(IList`1 chatMessages, ChatOptions options, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Program.<Main>$(String[] args) in /Users/minnbran/GitHub/Bedrock-MEAI-Sample/src/AiChatClient.Console/Program.cs:line 10
at Program.<Main>$(String[] args) in /Users/minnbran/GitHub/Bedrock-MEAI-Sample/src/AiChatClient.Console/Program.cs:line 10
at Program.<Main>(String[] args)
Code
using AiChatClient.Common;
using AiChatClient.Console;
using Amazon;
using Amazon.BedrockRuntime;
var bedrockService = new BedrockService(
new AmazonBedrockRuntimeClient(AwsCredentials.AccessKeyId, AwsCredentials.SecretAccessKey, RegionEndpoint.USWest1),
"anthropic.claude-3-haiku-20240307-v1:0");
await foreach (var response in bedrockService.GetStreamingResponseAsync("Is this working?", new(), CancellationToken.None))
{
Console.Write(response.Text);
}
Share
Improve this question
asked Mar 31 at 15:53
Brandon MinnickBrandon Minnick
15.5k16 gold badges81 silver badges144 bronze badges
1 Answer
Reset to default 0The correct region to use for Claude 3 Haiku is RegionEndpoint.USWest2
.
Long story short, you need to review the Regions Supported
column from the table where Amazon lists all of its Supported foundation models in Amazon Bedrock.
Supported foundation models in Amazon Bedrock
Copy/Paste the string
listed in the Amazon ID
column and use a RegionEndpoint
enum that corresponds to one listed in Regions Supported
column.
Code
using AiChatClient.Common;
using AiChatClient.Console;
using Amazon;
using Amazon.BedrockRuntime;
var bedrockService = new BedrockService(
new AmazonBedrockRuntimeClient(AwsCredentials.AccessKeyId, AwsCredentials.SecretAccessKey, RegionEndpoint.USWest2),
"anthropic.claude-3-haiku-20240307-v1:0");
await foreach (var response in bedrockService.GetStreamingResponseAsync("Is this working?", new(), CancellationToken.None))
{
Console.Write(response.Text);
}
More Information
Here's a blog post I wrote to help explain more: https://codetraveler.io/2025/03/25/introducing-awssdk-extensions-bedrock-meai-2/