Skip to main content
POST
/
images
/
generations
Create image generation
curl --request POST \
  --url https://dimilinks.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "prompt": "<string>",
  "model": "gpt-image-2",
  "n": 1,
  "size": "<string>",
  "resolution": "1k",
  "output_format": "<string>",
  "output_compression": 123,
  "background": "<string>",
  "moderation": "<string>",
  "wait_for_result": true,
  "image_urls": "<string>",
  "user": "<string>"
}
'
{
  "task_id": "img_xxx",
  "data": [],
  "created": 1777080000
}
使用 gpt-image-2 从文本生成图片。也可以通过 image_urls 携带参考图,实现图生图或风格迁移。
推荐加上 ?async=true。同步模式会等待图片完成后才返回,容易受到调用方超时影响。

请求地址

POST https://dimilinks.com/v1/images/generations?async=true

文生图示例

curl "https://dimilinks.com/v1/images/generations?async=true" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "一张赛博朋克风格的猫咪海报,霓虹灯,电影感",
    "n": 1,
    "size": "16:9",
    "resolution": "2k",
    "output_format": "png"
  }'

图生图示例

curl "https://dimilinks.com/v1/images/generations?async=true" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "保持人物主体一致,改成海边日落电影写真风格",
    "n": 1,
    "size": "16:9",
    "resolution": "4k",
    "image_urls": [
      "https://example.com/reference.png"
    ]
  }'

异步响应

{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": []
}
拿到 task_id 后,请调用 Retrieve image task 查询结果。

同步响应

同步模式会在图片完成后返回:
{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": [
    {
      "url": "/p/img/img_xxx/0?exp=1777166400000&sig=...",
      "file_id": "file_xxx"
    }
  ]
}

参数

参数类型默认值说明
modelstringgpt-image-2模型名称。
promptstring必填生图或编辑提示词。
ninteger1当前建议按 1 设计。接口会把过小或过大的值归一到支持范围。
sizestring1024x1024支持比例如 1:116:9,也支持像素如 3840x2160
resolutionstring推荐清晰度字段:1k2k4k
output_formatstring输出格式建议使用 pngjpegwebp
output_compressioninteger输出压缩质量,通常配合 jpegwebp
backgroundstring背景偏好,如 autotransparentopaque
moderationstring内容审核强度,如 autolow
userstring调用方用户标识,便于审计。
wait_for_resultbooleantruefalse 可进入异步提交。
image_urlsstring / array / objectJSON 参考图字段,最多 4 张。

开启异步的方式

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

参考图格式

推荐使用 image_urls
{
  "image_urls": [
    "https://example.com/ref.png",
    "data:image/png;base64,iVBORw0KGgo..."
  ]
}
也兼容 reference_imagesimagesimageimage_urlinput_imageinput_images

参考图限制

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

Authorizations

Authorization
string
header
required

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

Query Parameters

async
boolean

Set to true to submit an async image task.

wait_for_result
boolean

Set to false to submit an async image task.

compat
enum<string>

Set to apimart for APIMart-compatible response shape.

Available options:
apimart

Body

application/json
prompt
string
required
model
string
default:gpt-image-2
n
integer
default:1
Required range: 1 <= x <= 4
size
string
Examples:

"1:1"

"16:9"

"3840x2160"

resolution
enum<string>
Available options:
1k,
2k,
4k
output_format
string
Examples:

"png"

"jpeg"

"webp"

output_compression
integer
background
string
Examples:

"auto"

"transparent"

"opaque"

moderation
string
Examples:

"auto"

"low"

wait_for_result
boolean
image_urls
user
string

Response

Image generation result or async submission

task_id
string
required
Example:

"img_xxx"

data
object[]
required
Example:
[]
created
integer
Example:

1777080000