跳转到主要内容
POST
Create image generation
gpt-image-2 是 DimiLinks 的图片生成模型,支持文生图与图生图。可以通过 image_urls 字段携带参考图,最多 9 张。
推荐加上 ?async=true。同步模式会等图片完成后才返回,更容易被网关或客户端超时打断。

请求地址

文生图示例

图生图示例

异步响应

拿到 task_id 后,请调用 Retrieve image task 查询结果。

同步响应

同步模式会在图片完成后返回:

结果字段说明

data[].url 是图片结果地址,请按以下规则处理:
  • /p/img/...:相对路径,展示或下载前补成 https://lmage2.dimilinks.com。该路径不需要 Bearer,URL 自带签名和过期时间。
  • https://lmage2.dimilinks.com/p/img/...:完整图片链接,可直接请求或展示。
异步任务查询返回的图片结果位于任务响应的 data.data[],不是 result.data[]。图片 URL 中的 img_xxx 是图片资源 ID,不是提交接口返回的公开任务 ID。

参数

开启异步的方式

任一方式命中即可进入异步模式:
  • 查询参数:?async=true
  • 查询参数:?wait_for_result=false
  • 请求头:Prefer: respond-async
  • 请求体:"wait_for_result": false

参考图格式

推荐使用 image_urls:
也兼容 reference_images、images、image、image_url、input_image 和 input_images。

参考图限制

  • 同一次请求最多 9 张参考图。
  • 单张参考图最大 20 MB。
  • 支持 HTTP(S) URL、Data URL 和纯 base64。
  • 浏览器 blob: URL 不能直接传入,请先上传到你的服务端或转成 Data URL。

清晰度档位的能力差异

具体单价以控制台「价格」页为准;不同档位的价格独立计算。

授权

Authorization
string
header
必填

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

查询参数

async
boolean

Set to true to submit an async image task.

wait_for_result
boolean

Set to false to submit an async image task.

请求体

application/json
prompt
string
必填
model
string
默认值:gpt-image-2
n
integer
默认值:1

1k resolution allows n=1 only; 2k and 4k allow up to 4.

必填范围: 1 <= x <= 4
size
string
示例:

"1:1"

"16:9"

"3840x2160"

resolution
enum<string>
可用选项:
1k,
2k,
4k
output_format
string
示例:

"png"

"jpeg"

"webp"

output_compression
integer
background
string
示例:

"auto"

"transparent"

"opaque"

moderation
string
示例:

"auto"

"low"

wait_for_result
boolean
image_urls
mask_url
string
response_format
string
示例:

"b64_json"

user
string

响应

Image generation result or async submission

task_id
string
必填
示例:

"task_xxx"

data
object[]
必填
示例:
created
integer
示例:

1777080000