Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: 5...
错误信息
InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: 53bc3f93-3c32-4e36-8b4f-f66c622b3960, ValidationException: The provided model identifier is invalid.
AI 解决方案
🔍 错误分析
1. 🌐 错误翻译
原文:InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: 53bc3f93-3c32-4e36-8b4f-f66c622b3960, ValidationException: The provided model identifier is invalid.
译文:InvokeModel:操作错误 Bedrock 运行时:调用模型,https 响应错误 状态码:400,请求ID:53bc3f93-3c32-4e36-8b4f-f66c622b3960,验证异常:提供的模型标识符无效。
2. 🎯 原因分析
InvokeModel 接口时,传入的模型标识符(model identifier)不符合要求,导致验证失败3. 💡 解决方案
检查并更正模型标识符,确保其为 Amazon Bedrock 支持的合法模型 ID(如
amazon.titan-embed-text-v1、amazon.titan-text-express-v1 等),示例修复代码如下:``语言
import boto3
from botocore.exceptions import ClientError
初始化 Bedrock 客户端
bedrock = boto3.client(
service_name='bedrock-runtime',
region_name='us-east-1' # 替换为实际区域
)
合法的 Bedrock 模型标识符(根据需求调整)
model_id = "amazon.titan-text-express-v1"
try:
response = bedrock.invoke_model(
modelId=model_id,
body='{"inputText": "测试文本"}',
contentType='application/json',
accept='application/json'
)
print("调用成功:", response)
except ClientError as e:
print("调用失败:", e.response['Error']['Message'])
`
4. 🛡️ 预防措施
接口,获取当前区域支持的合法模型标识符,避免硬编码错误的 ID、anthropic.、ai21. 等前缀开头),确保参数合法后再发起请求