":{"message":"InvokeModelWithResponseStream: operation error Bedrock Runtime: In...

2026年03月28日 16:34 状态: processing

🚨 错误信息

{"error":{"message":"InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: ce38b411-0e60-4b6b-b496-f4339c4081a4, ValidationException: `temperature` and `top_p` cannot both be specified for this model. Please use only one.","type":"aws_invoke_error","param":"","code":"aws_invoke_error"}}

🤖 AI解决方案

报错分析报告

1.错误翻译


``
原文:
temperature and top_p cannot both be specified for this model. Please use only one.
译文:
temperature(温度)和top_p(核采样率)参数不能同时为该模型指定,请仅使用其中一个。
`

2.原因分析


  • 根本原因:调用Bedrock模型时,同时传入了互斥参数temperaturetop_p,违反模型约束。

  • 发生位置InvokeModelWithResponseStream`操作的参数配置中,两个参数被同时指定。
  • 3.解决方案


    以Python boto3调用为例,移除其中一个参数(二选一):
    python
    import boto3

    client = boto3.client("bedrock-runtime")

    response = client.invoke_model_with_response_stream(
    modelId="your-model-id",
    body={
    "prompt": "你的输入",
    "max_tokens": 200,
    # 仅保留temperature 或 top_p 中的一个
    "temperature": 0.7, # 示例:保留temperature
    # "top_p": 0.9, # 注释或删除top_p
    },
    contentType="application/json",
    accept="application/json"
    )

    4. 预防措施


  • 查文档优先:调用模型前,务必查阅AWS Bedrock对应模型的[官方参数说明](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html),确认支持的参数组合。

  • 参数校验:使用静态分析工具(如Pylint自定义规则)或运行时校验函数,提前拦截互斥参数。
  • ---
    如需进一步分析其他报错,请提供具体错误信息。