gpt-image-2

gpt-image-2
图像OpenAIgpt-image-2gpt-image-2
GPT-Image 2 是 OpenAI 的图像生成与编辑模型,适合文字生成图片、参考图改图、商品图优化、海报素材、创意概念图和营销视觉制作。它适合需要较高画面质量、指令理解和商业可用性的图片生成场景。

Authentication

Base URL
https://host.docker.internal:8000
Authorization
Authorization: Bearer YOUR_API_KEY
Content-Type
application/json
Model name
gpt-image-2

Integration protocols

Why this protocol

适合已有 OpenAI Images 图片生成接口代码,且希望同步拿到图片结果的用户。

Endpoint
POST/v1/images/generations
Authorization: Bearer YOUR_API_KEYContent-Type: application/json

Request / Response JSON

Request examples
Image URLreference_images[]
{
  "model": "gpt-image-2",
  "prompt": "生成一张产品海报,白色背景,商业摄影风格",
  "size": "2752x1536",
  "response_format": "url",
  "reference_images": [
    "https://example.com/reference.png"
  ]
}
Base64 imagereference_images[].mime_type + data_base64
{
  "model": "gpt-image-2",
  "prompt": "生成一张产品海报,白色背景,商业摄影风格",
  "size": "2752x1536",
  "response_format": "url",
  "reference_images": [
    {
      "mime_type": "image/jpeg",
      "data_base64": "BASE64_IMAGE_DATA"
    }
  ]
}
Response example
{
  "created": 1710000000,
  "data": [
    {
      "url": "https://example.com/output.png"
    }
  ]
}

Request / Response schema

// INPUT SCHEMA
FieldTypeRequired
modelstringY
promptstringY
sizestringY
response_formatstringY
reference_imagesarrayY
// RESPONSE SCHEMA
FieldTypeRequired
createdintegerY
dataarrayY
data[]objectY
data[].urlstringY

Code examples

cURLrequest.sh
curl -X POST "https://host.docker.internal:8000/v1/images/generations" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
  "model": "gpt-image-2",
  "prompt": "生成一张产品海报,白色背景,商业摄影风格",
  "size": "2752x1536",
  "response_format": "url",
  "reference_images": [
    "https://example.com/reference.png"
  ]
}'

# Upload reference cURL
curl -X POST "https://host.docker.internal:8000/v1/files/upload" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "kind=image" \
  -F "purpose=reference" \
  -F "file=@demo.png"
Why this protocol

适合需要提交任务并轮询状态的图像、视频、音频生成工作流。

Endpoint
POST/v1/jobs
Authorization: Bearer YOUR_API_KEYContent-Type: application/json

Request / Response JSON

// REQUEST
{
  "model": "gpt-image-2",
  "input": {
    "prompt": "生成一张产品海报,白色背景,商业摄影风格",
    "image_url": "https://example.com/input.png",
    "reference_images": [
      "https://example.com/reference.png"
    ],
    "mask": "https://example.com/mask.png",
    "size": "2752x1536",
    "quality": "medium",
    "output_format": "png",
    "response_format": "url",
    "background": "auto",
    "n": 1,
    "user": "user-123",
    "aspect_ratio": "16:9"
  }
}
// RESPONSE
{
  "id": "job_example",
  "object": "job",
  "status": "processing",
  "model": "gpt-image-2",
  "created": 1710000000,
  "request_id": "req_example"
}

Request / Response schema

// INPUT SCHEMA
FieldTypeRequired
promptstringY
image_urlimageN
reference_imagesarrayN
maskimageN
sizestringN
qualityenumN
output_formatenumN
response_formatenumN
backgroundenumN
nintegerN
userstringN
aspect_ratioenumN
// RESPONSE SCHEMA
FieldTypeRequired
idstringN
statusenumN
modelstringN
output.images[].urlimageN
output.images[].mime_typestringN

Code examples

cURLrequest.sh
curl -X POST "https://host.docker.internal:8000/v1/jobs" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
  "model": "gpt-image-2",
  "input": {
    "prompt": "生成一张产品海报,白色背景,商业摄影风格",
    "image_url": "https://example.com/input.png",
    "reference_images": [
      "https://example.com/reference.png"
    ],
    "mask": "https://example.com/mask.png",
    "size": "2752x1536",
    "quality": "medium",
    "output_format": "png",
    "response_format": "url",
    "background": "auto",
    "n": 1,
    "user": "user-123",
    "aspect_ratio": "16:9"
  }
}'

# Upload reference cURL
curl -X POST "https://host.docker.internal:8000/v1/files/upload" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "kind=image" \
  -F "purpose=reference" \
  -F "file=@demo.png"

# Poll status cURL
# Replace job_example with the task_id returned by the submit call
curl -X GET "https://host.docker.internal:8000/v1/jobs/job_example" \
  -H "Authorization: Bearer YOUR_API_KEY"