Skip to content

OpenAI 生成图片

/v1/images/generations 是 OpenAI Images API 兼容的同步生图接口。调用方会在同一个 HTTP 请求中等待上游返回。

接口说明

项目
MethodPOST
Path/v1/images/generations
Content-Typeapplication/json
认证Authorization: Bearer YOUR_API_KEY
平台要求OpenAI 平台分组,且分组启用生图能力

请求参数

参数类型必填说明
modelstring图片模型。未传时默认 gpt-image-2。必须是 gpt-image-* 系列。
promptstring生图提示词。
sizestring输出尺寸,例如 1024x1024
ninteger生成图片数量,默认 1,必须大于 0
response_formatstring响应格式,常用 b64_json
streamboolean是否流式返回,按上游能力透传。
qualitystringOpenAI 原生图片参数,按上游能力透传。
backgroundstringOpenAI 原生图片参数,按上游能力透传。
output_formatstringOpenAI 原生图片参数,按上游能力透传。
output_compressionintegerOpenAI 原生图片参数,按上游能力透传。
moderationstringOpenAI 原生图片参数,按上游能力透传。
stylestringOpenAI 原生图片参数,按上游能力透传。

请求示例

bash
curl https://llmapi.site/v1/images/generations \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-image-2",
    "prompt": "a product photo of a ceramic coffee cup on a white table",
    "size": "1024x1024",
    "n": 1,
    "response_format": "b64_json"
  }'

响应示例

json
{
  "created": 1779912000,
  "data": [
    {
      "b64_json": "..."
    }
  ]
}

常见错误

非 OpenAI 分组调用:

json
{
  "error": {
    "type": "not_found_error",
    "message": "Images API is not supported for this platform"
  }
}

模型不是图片模型:

json
{
  "error": {
    "type": "invalid_request_error",
    "message": "images endpoint requires an image model"
  }
}

适用边界

  • 本接口只适用于 OpenAI Images API 兼容请求。
  • Gemini native 图片请求应使用 /v1beta/models/{model}:generateContent
  • 长耗时或生产批量任务建议使用异步生图接口。