API 目录

创建 gpt-image-1

POST
/v1/images/generations

创建图像(gpt-image-1)

POST https://www.vortapapi.com/v1/images/generations

根据文本提示词生成一张或多张图像。该接口兼容 OpenAI Images API,可用于调用 gpt-image-1 等图像生成模型。

请求头

名称必填说明
Content-Type固定为 application/json
Accept建议设置为 application/json
Authorization使用 Bearer Token,例如:Bearer sk-***

请求体参数

参数类型必填说明
modelstring要使用的图像模型,例如 gpt-image-1
promptstring图像生成提示词,用于描述希望生成的画面内容。
ninteger生成图片数量。默认值通常为 1
sizestring图片尺寸。gpt-image-1 常用值包括 1024x10241536x10241024x1536auto
qualitystring图像质量,可使用 autohighmediumlow
backgroundstring背景类型,可使用 autotransparentopaque
output_formatstring输出图片格式,例如 pngjpegwebp
output_compressioninteger输出压缩质量,适用于 jpegwebp,取值范围通常为 0100
moderationstring内容审核强度,例如 autolow
userstring终端用户标识,可用于追踪和风控。

请求示例

curl https://www.vortapapi.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "gpt-image-1",
    "prompt": "一只穿着宇航服的橘猫站在月球表面,背景是蓝色地球,电影感光影",
    "size": "1024x1024",
    "quality": "high",
    "n": 1
  }'

响应示例

gpt-image-1 通常会返回 Base64 编码的图片数据,可从 data[].b64_json 中读取并保存为图片文件。

{
  "created": 1713833628,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}

响应字段

字段类型说明
createdinteger响应创建时间,Unix 时间戳。
dataarray生成结果列表。
data[].b64_jsonstringBase64 编码后的图片内容。
data[].revised_promptstring若模型对提示词进行了改写,可能返回该字段。

保存 Base64 图片示例

import base64
import requests

response = requests.post(
    "https://www.vortapapi.com/v1/images/generations",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer sk-***"
    },
    json={
        "model": "gpt-image-1",
        "prompt": "一座漂浮在云层之上的未来城市,清晨阳光,超写实风格",
        "size": "1024x1024",
        "n": 1
    }
)

result = response.json()
image_base64 = result["data"][0]["b64_json"]

with open("image.png", "wb") as f:
    f.write(base64.b64decode(image_base64))