POST /v1/videos/v1/videos 接口调用 GPT 图片生成能力(与视频生成共用接口,通过 model 参数区分),支持文生图和图生图两种模式,采用异步任务方式,先提交返回任务 ID,再轮询获取结果。aspect_ratio 传入固定比例字符串(如 9:16、16:9 等),精确控制输出比例size 传入像素尺寸字符串(如 "1915x821"),直接指定宽高像素——与 aspect_ratio 二选一,不需要同时传"auto",或两个参数均不传——两者等价,均根据提示词内容自动推断,无固定比例;提示词中若写明了比例(如"竖屏 9:16"),模型也会据此生成| model 参数 | 说明 |
|---|---|
gpt-image-2 | GPT 图片生成(标准档) |
gpt-image-2-2K | 2K 分辨率 |
gpt-image-2-4K | 4K 分辨率 |
/v1/videos 异步流程,仅 model 不同;下游计费与上游路由以 model 区分档位。| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer YOUR_API_KEY |
| Content-Type | string | 是 | application/json |
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型名称,取值为 gpt-image-2、gpt-image-2-2K、gpt-image-2-4K 之一(大小写须与上表一致,其中 2K/4K 为大写 K) |
| prompt | string | 是 | 文本提示词 |
| aspect_ratio | string | 否 | 宽高比。传固定比例字符串(见下表支持的 10 种值)则精确控制;传 "auto" 或不传则根据提示词内容自动推断,没有固定比例。与 size 二选一 |
| size | string | 否 | 像素尺寸,格式 "宽x高"(如 "1456x816"、"1024x1024")。传此参数可替代 aspect_ratio 直接指定像素比,两者二选一 |
| images | string[] | 否 | 参考图片数组(支持 Base64 或 URL),最多 8 张。传此参数为图生图模式,不传或传空数组为文生图模式 |
aspect_ratio 支持的值| 值 | 方向 | 适用场景 |
|---|---|---|
auto | 自动 | 不指定比例,根据提示词内容自动推断(与不传等价) |
1:1 | 正方形 | 通用、社交媒体 |
16:9 | 横向(宽屏) | 横屏内容、PC 端 |
9:16 | 竖向 | 短视频、手机竖屏 |
4:3 | 横向 | 传统屏幕 |
3:4 | 竖向 | 竖屏内容 |
3:2 | 横向 | 摄影常用 |
2:3 | 竖向 | 竖版海报 |
5:4 | 横向 | 大幅横图 |
4:5 | 竖向 | Instagram 竖图 |
21:9 | 超宽横向 | 影院宽幅 |
宽高比控制方式对比
方式 用法 效果 像素尺寸 "size": "1456x816"直接按像素宽高精确控制,与 aspect_ratio二选一固定比例 "aspect_ratio": "9:16"精确输出指定比例 自动推断 "aspect_ratio": "auto"或两者均不传根据提示词内容自动决定,无固定比例 提示词描述 不传或传 "auto",prompt 中写明比例模型从提示词中读取比例并遵循
images 数组元素传法| 方式 | 示例 |
|---|---|
| 图片 URL | "https://example.com/reference.jpg" |
| Base64 | "data:image/jpeg;base64,/9j/4AAQSkZJRg..." |
注意:传入图片 URL 时,网关会自动将其下载并转为 Base64 后发给上游,请确保 URL 为可公网访问的图片直链。
{
"model": "gpt-image-2",
"prompt": "生成抖音带货风格主图,主体 xxx",
"aspect_ratio": "9:16"
}{
"model": "gpt-image-2",
"prompt": "一只可爱的柴犬坐在草地上",
"aspect_ratio": "auto"
}传 "auto"与不传aspect_ratio完全等价,由官方根据内容自动决定比例,无固定值。
{
"model": "gpt-image-2",
"prompt": "一只可爱的柴犬坐在草地上"
}{
"model": "gpt-image-2",
"prompt": "生成一张 16:9 横屏风景图,美丽的日出,金色阳光洒在 宁静湖面上,远处连绵山脉",
"aspect_ratio": "auto"
}不指定固定比例,模型从提示词中读取"16:9"并按此生成。
{
"model": "gpt-image-2",
"prompt": "生成抖音带货风格主图,主体 xxx",
"size": "1456x816"
}直接传像素宽高,无需换算比例字符串,与 aspect_ratio二选一。常见组合示例:横屏宽幅: "1456x816"(约 16:9)竖屏手机: "816x1456"(约 9:16)正方形: "1024x1024"自定义: "1915x821"(约 7:3,超宽横向)
{
"model": "gpt-image-2-4K",
"prompt": "生成抖音带货风格主图,主体 xxx",
"aspect_ratio": "9:16"
}将 model改为gpt-image-2-2K或gpt-image-2-4K即可,aspect_ratio用法与标准档相同。
{
"model": "gpt-image-2",
"prompt": "将这张图片转换成油画风格",
"aspect_ratio": "9:16",
"images": [
"data:image/jpeg;base64,/9j/4AAQSkZJRg...",
"data:image/png;base64,iVBORw0KGgoAAAANSU..."
]
}{
"model": "gpt-image-2",
"prompt": "将这张图片转换成油画风格",
"aspect_ratio": "16:9",
"images": [
"https://example.com/images/reference1.jpg",
"https://example.com/images/reference2.png"
]
}| 参数名 | 类型 | 说明 |
|---|---|---|
| id | string | 任务 ID,格式:task_xxxx |
| object | string | 对象类型,固定值:image |
| model | string | 使用的模型名称 |
| status | string | 任务状态:queued(排队中)、in_progress(处理中)、completed(已完成)、failed(失败) |
| progress | number | 任务进度,0–100 |
| created_at | number | 创建时间戳(秒) |
| completed_at | number | 完成时间戳(秒),仅在 completed 或 failed 状态返回 |
| url | string | 生成的图片 URL,仅在 completed 状态返回 |
| error | object | 错误信息,仅在 failed 状态返回 |
| error.message | string | 失败原 因描述 |
| error.code | string | 错误码,如 upstream_error |
{
"id": "task_1776831820897",
"object": "image",
"model": "gpt-image-2",
"status": "queued",
"progress": 0,
"created_at": 1709876543
}{
"id": "task_1776831820897",
"object": "image",
"model": "gpt-image-2",
"status": "in_progress",
"progress": 10,
"created_at": 1709876543
}{
"id": "task_1776831820897",
"object": "image",
"model": "gpt-image-2",
"status": "completed",
"progress": 100,
"created_at": 1709876543,
"completed_at": 1709876598,
"url": "https://example.com/uploads/gpt-images/task_1776831820897.png"
}{
"id": "task_1776831820897",
"object": "image",
"model": "gpt-image-2",
"status": "failed",
"created_at": 1718123456,
"completed_at": 1718123456,
"progress": 100,
"error": {
"message": "上游任务失败原因",
"code": "upstream_error"
}
}GET /v1/videos/{task_id}status 字段判断任务是否完成:queued / in_progress:任务未完成,继续轮询completed:任务完成,从 url 字段获取图片地址failed:任务失败,从 error.message 获取错误原因/v1/videos 接口,与视频生成共用,通过 model 参数区分;GPT 图系列为 gpt-image-2、gpt-image-2-2K、gpt-image-2-4Kaspect_ratio、size、images 均为顶层字段,直接放在请求体根对象中size(如 "1915x821")→ 直接按像素宽 高控制,与 aspect_ratio 二选一"9:16")→ 精确控制输出比例"auto" 或两者均不传→ 完全等价,根据提示词内容自动推断,无固定比例;提示词中若描述了比例,模型会据此生成data:image/jpeg;base64,)images 或传空数组 = 文生图模式images 包含图片(Base64 或 URL)= 图生图模式GET /v1/videos/{task_id} 查询任务进度和结果,建议轮询间隔 2~5 秒