You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWSSDK.Extensions.Bedrock.MEAI调用Claude遇模型ID无效错误

解决AWS Bedrock调用Claude时的模型ID无效错误

出现Amazon.BedrockRuntime.Model.ValidationException: The provided model identifier is invalid错误的核心原因是你使用的模型ID格式不正确。AWS Bedrock要求使用带版本标识的完整模型ID,而非通用的anthropic.claude。

正确的Claude模型ID示例

AWS Bedrock上的Anthropic Claude模型需指定具体版本,常见的有效ID包括:

  • Claude 3系列(最新):
    • Claude 3 Sonnet: anthropic.claude-3-sonnet-20240229-v1:0
    • Claude 3 Haiku: anthropic.claude-3-haiku-20240307-v1:0
    • Claude 3 Opus: anthropic.claude-3-opus-20240229-v1:0
  • Claude 2系列:
    • Claude 2.1: anthropic.claude-v2:1
    • Claude 2: anthropic.claude-v2

修改后的代码示例

将模型ID替换为上述有效ID之一,比如使用Claude 3 Sonnet:

var bedrockService = new BedrockService(
    new AmazonBedrockRuntimeClient("My AWS Credentials Access ID","My AWS Credentials Secret Access Key", RegionEndpoint.USEast1),
    "anthropic.claude-3-sonnet-20240229-v1:0");

await foreach (var response in bedrockService.GetStreamingResponseAsync("Is this working?", new(), CancellationToken.None))
{
    Console.Write(response.Text);
}

额外注意事项

  • 确保你的AWS账号已在us-east-1区域启用了目标Claude模型(需在Bedrock控制台的「模型访问」页面申请启用)
  • 验证IAM权限包含bedrock:InvokeModelWithResponseStream动作,且资源范围覆盖你使用的模型ID

内容的提问来源于stack exchange,提问作者Brandon Minnick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 14:37:35