Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode:...

2026年01月14日 22:26 状态: processing

🚨 错误信息

InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 4e67b173-1c93-45fb-af3d-d8607b263f4b, ValidationException: ***.***.***.***.***.***.***.data: At least one of the image dimensions exceed max allowed size: 8000 pixels (request id: 20260114221834460715626dr2v9FvG) (request id: 20260114221834153245053CBTeJJKQ) (request id: 20260114221723960073396TZh2K7Cs) (request id: 20260114221723920740819WsLLlTRz)

🤖 AI解决方案

报错分析报告

1. 错误翻译


原文:ValidationException: ......*.data: At least one of the image dimensions exceed max allowed size: 8000 pixels
译文:验证异常:图像数据的至少一个维度超过了允许的最大尺寸:8000像素

2. 原因分析

根本原因:您向Amazon Bedrock服务提交的图像尺寸超出了服务限制。

详细分析

  • Amazon Bedrock的InvokeModelWithResponseStream API对输入图像有尺寸限制

  • 图像的最大允许尺寸为8000像素(包括宽度和高度)

  • 您的图像宽度或高度至少有一边超过了8000像素

  • 错误发生在Bedrock Runtime服务验证输入参数阶段
  • 3. 解决方案

    Python解决方案示例:


    python
    from PIL import Image
    import io

    def resize_image_to_fit_limit(image_path, max_dimension=8000):
    """
    调整图像尺寸以符合Bedrock限制
    """
    # 打开图像
    img = Image.open(image_path)
    width, height = img.size

    # 检查是否需要调整
    if max(width, height) > max_dimension:
    # 计算缩放比例
    scale = max_dimension / max(width, height)
    new_width = int(width * scale)
    new_height = int(height * scale)

    # 调整图像尺寸
    img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)
    print(f"图像已从 {width}x{height} 调整为 {new_width}x{new_height}")

    # 将图像转换为字节流
    img_byte_arr = io.BytesIO()
    img.save(img_byte_arr, format=img.format)

    return img_byte_arr.getvalue()

    使用方法


    resized_image_data = resize_image_to_fit_limit("your_image.jpg")

    JavaScript/Node.js解决方案:


    ``javascript
    const sharp = require('sharp');

    async function resizeImageForBedrock(inputPath, maxDimension = 8000) {
    const metadata = await sharp(inputPath).metadata();
    const { width, height } = metadata;

    if (Math.max(width, height) > maxDimension) {
    const scale = maxDimension / Math.max(width, height);
    const newWidth = Math.floor(width * scale);
    const newHeight = Math.floor(height * scale);

    console.log(
    图像已从 ${width}x${height} 调整为 ${newWidth}x${newHeight});

    return await sharp(inputPath)
    .resize(newWidth, newHeight)
    .toBuffer();
    }

    return await sharp(inputPath).toBuffer();
    }

    // 使用方法
    const imageBuffer = await resizeImageForBedrock('your_image.jpg');

    4. ️ 预防措施

    最佳实践建议:


  • 预检查图像尺寸:在处理图像前,先检查尺寸是否符合服务限制

  • 批量处理验证:如果处理多张图像,实现自动化的尺寸检查和调整流程
  • 推荐工具:


  • 图像处理库:Python的PIL/Pillow库,Node.js的sharp库

  • 在线检查工具:使用免费在线工具检查图像尺寸(如picresize.com)

  • 脚本自动化:创建预处理脚本,自动调整超限图像
  • 开发提示:


    python

    预检查函数


    def check_image_size(image_path, max_dim=8000):
    from PIL import Image
    with Image.open(image_path) as img:
    w, h = img.size
    if max(w, h) > max_dim:
    raise ValueError(f"图像尺寸{w}x{h}超过限制{max_dim}像素")
    return True
    ``

    建议您在调用Bedrock API前添加图像尺寸预检查,避免不必要的API调用失败和计费。