跳转到主要内容

GPT Image

POST /v1/images/generations
使用 gpt-image-1 模型生成图像,兼容 OpenAI Images API 格式。

生成图像

请求参数

参数类型必填说明
modelstring固定为 gpt-image-1
promptstring图像描述提示词
ninteger生成数量,默认 1
sizestring图片尺寸:1024x1024(默认)、1536x10241024x1536auto
qualitystring质量:auto(默认)、lowmediumhigh
backgroundstring背景:auto(默认)、transparentopaque
output_formatstring输出格式:png(默认)、jpegwebp

请求示例

curl -X POST https://crazyrouter.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-image-1",
    "prompt": "一只穿着宇航服的猫咪在月球上行走,背景是地球",
    "n": 1,
    "size": "1024x1024",
    "quality": "high"
  }'

响应示例

{
  "created": 1709123456,
  "data": [
    {
      "url": "https://crazyrouter.com/files/image_abc123.png",
      "revised_prompt": "A cat wearing a spacesuit walking on the moon's surface with Earth visible in the background"
    }
  ]
}

编辑图像

POST /v1/images/edits
基于已有图像进行编辑,支持遮罩区域编辑。

请求参数

参数类型必填说明
modelstring固定为 gpt-image-1
imagefile原始图片文件(multipart)
promptstring编辑描述
maskfile遮罩图片,透明区域为需要编辑的部分
ninteger生成数量
sizestring输出尺寸

请求示例

Python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://crazyrouter.com/v1"
)

response = client.images.edit(
    model="gpt-image-1",
    image=open("original.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="在天空中添加一道彩虹",
    n=1,
    size="1024x1024"
)

print(response.data[0].url)
GPT Image 支持透明背景输出,设置 background: "transparent" 并使用 PNG 格式即可。