400 {"error":{"type":"<nil>","message":"InvokeModelWithResponseStream: operation...

2026年04月07日 08:59 processing

错误信息

API Error: 400 {"error":{"type":"<nil>","message":"InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 94b8cd49-3277-42a9-a7cf-57cc0dfca933, ValidationException: system.2.cache_control.***.scope: Extra inputs are not permitted (request id: 202604070858489984462149l9e8ycT)"},"type":"error"}

AI 解决方案

报错分析报告

1.错误翻译


原文:ValidationException: system.2.cache_control.***.scope: Extra inputs are not permitted
译文:验证异常:system.2.cache_control.***.scope:不允许额外输入

2. 原因分析


  • 根本原因:调用Bedrock Runtime的InvokeModelWithResponseStream接口时,请求中cache_control.scope字段包含未允许的额外输入

  • 发生位置:API请求的cache_control配置段,具体是system.2.cache_control..scope参数违规。
  • 3.解决方案


    移除cache_control.scope中的额外输入,仅保留官方允许的字段。以下是Python示例(通用修复逻辑):
    import boto3
    
    client = boto3.client("bedrock-runtime")
    
    # 修复后的请求:移除cache_control.scope的额外输入
    response = client.invoke_model_with_response_stream(
        modelId="your-model-id",
        body={
            "prompt": "你的有效提示",
            "cache_control": {
                # 仅保留允许的字段(如type),删除***及多余scope)
                "type": "ephemeral"  # 示例:按官方文档设置合法值
            }
        }
    )
    

    4. 预防措施


  • 参数校验:调用API前用[JSON Schema](https://json-schema.org/)校验请求体,确保无额外字段。

  • 文档对齐*:参考[AWS Bedrock官方文档](https://docs.aws.amazon.com/bedrock/latest/userguide/api-reference.html),明确cache_control等字段的允许值。
  • ---
    请确认修复后是否仍有报错,如需进一步分析请提供更新后的错误信息。