] Model claude-sonnet-5 failed: Error code: 400 - {'error': {'message': 'InvokeM...

2026年07月13日 14:16 41.34 秒 success

错误信息

[API Error] Model claude-sonnet-5 failed: Error code: 400 - {'error': {'message': 'InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: 8e9629f8-ba6f-4e7d-8f84-a2a173e79434, api error ValidationException: `temperature` is deprecated for this model. (request id: 202607130615274647893598268d9d6dJmS38dt) (request id: 202607130615274092129898268d9d6aPexcPI9) (request id: 202607130615261599427620VmZ843S)', 'type': '<nil>', 'param': '', 'code': None}}

AI 解决方案

🔍 报错分析

1. 🌐 错误翻译


原文:[API Error] Model claude-sonnet-5 failed: Error code: 400 - {'error': {'message': 'InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: 8e9629f8-ba6f-4e7d-8f84-a2a173e79434, api error ValidationException: `temperature` is deprecated for this model. (request id: 202607130615274647893598268d9d6dJmS38dt) (request id: 202607130615274092129898268d9d6aPexcPI9) (request id: 202607130615261599427620VmZ843S)', 'type': '<nil>', 'param': '', 'code': None}}
译文:[API 错误] Model claude-sonnet-5 失败:错误代码:400 - {'error': {'message': 'InvokeModel: 操作错误 Bedrock Runtime: InvokeModel,https 响应错误 StatusCode: 400, RequestID: 8e9629f8-ba6f-4e7d-8f84-a2a173e79434, api 错误 ValidationException: `temperature` 参数对于此模型已弃用。(请求 id: 202607130615274647893598268d9d6dJmS38dt)(请求 id: 202607130615274092129898268d9d6aPexcPI9)(请求 id: 202607130615261599427620VmZ843S)', 'type': '<nil>', 'param': '', 'code': None}}

2. 🎯 原因分析


核心原因:调用 Claude Sonnet 5 模型时,请求参数中包含已弃用的 temperature 参数。

错误细节

  • 错误类型:ValidationException(验证异常)

  • 错误位置:Bedrock Runtime 的 InvokeModel 操作

  • 关键信息:temperature 参数对该模型已不再支持,属于无效参数
  • 3. 💡 解决方案


    移除请求中的 temperature 参数即可。以下是修复后的请求示例(以常用调用方式为例):

    // 移除 temperature 参数后的请求配置示例
    const requestConfig = {
      modelId: 'anthropic.claude-sonnet-5',
      body: JSON.stringify({
        prompt: '你的提示词内容',
        max_tokens: 4096,
        // 以下参数根据实际需求保留,仅移除 temperature
        // temperature: 0.7,  // 这一行需要删除
        // 其他允许的参数...
      }),
      contentType: 'application/json',
    };
    
    // 发起请求(示例,具体调用方式根据你使用的SDK调整)
    bedrockRuntimeClient.invokeModel(requestConfig).then(response => {
      // 处理响应
    }).catch(error => {
      console.error('请求失败:', error);
    });
    

    4. 🛡️ 预防措施


  • 参数兼容性检查:调用新模型前,务必查阅对应模型的官方参数文档,确认支持的参数列表,避免使用已弃用或不支持的参数。

  • 参数预验证:开发阶段可通过 SDK 提供的参数校验功能或在请求发送前手动过滤无效参数,减少线上报错概率。

  • 版本追踪:关注模型版本更新,模型厂商可能会迭代调整参数支持策略,及时更新代码适配最新规则。