Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode:...
错误信息
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服务提交的图像尺寸超出了服务限制。
详细分析:
InvokeModelWithResponseStream API对输入图像有尺寸限制3. 解决方案
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解决方案:
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. ️ 预防措施
最佳实践建议:
推荐工具:
开发提示:
# 预检查函数
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调用失败和计费。