400

图片生成参数报错:size 不支持、n 太大、缺少 prompt

图片接口对尺寸、数量都有限制。报错信息会写清楚是哪一项,照着改就行。

报错原文2026-10-23 实测

size 填了不支持的尺寸
{
  "error": {
    "message": "image size/quality '123x456' / 'low' is not priced for this model",
    "type": "invalid_request_error",
    "param": null,
    "code": "image_size_not_priced"
  }
}
一次要 50 张
{
  "error": {
    "message": "'n' must be at most 4 for image generation",
    "type": "invalid_request_error",
    "param": null,
    "code": "image_n_too_large"
  }
}
没写 prompt
{
  "error": {
    "message": "prompt is required and must be a non-empty string",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_request"
  }
}

原因

我们复现了三种:

  • size 填 123x456 这种非标准尺寸,返回 image_size_not_priced。图片按尺寸和质量计价,不在价目表里的尺寸直接被拒绝;
  • n 填 50,返回“最多 4 张”;
  • 没有 prompt,或 prompt 是空字符串。

排查步骤

  1. size 使用服务商文档列出的标准尺寸,比如 1024x1024。
  2. n 不超过 4;需要更多张就分批请求。
  3. prompt 不能为空,从表单读取时先去掉首尾空白再判断。

正确写法

{"model": "gpt-image-2.5", "prompt": "…", "size": "1024x1024", "n": 1}