Skip to main content
本页演示最推荐的异步调用方式。请在服务端保存 API Key,不要把完整密钥放进浏览器页面或移动端安装包。

1. 准备 API Key

把你的密钥保存为环境变量:
export DIMILINKS_API_KEY="sk-..."
所有 /v1/* 请求都需要 Bearer Token:
Authorization: Bearer <DIMILINKS_API_KEY>
Content-Type: application/json

2. 提交生成任务

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"
  }'
默认异步响应会返回任务 ID:
{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": []
}

3. 轮询任务状态

curl "https://dimilinks.com/v1/tasks/img_xxx" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY"
任务完成后读取 result.data[].url
{
  "id": "img_xxx",
  "task_id": "img_xxx",
  "object": "image.task",
  "status": "succeeded",
  "progress": 100,
  "result": {
    "created": 1777080000,
    "data": [
      {
        "url": "/p/img/img_xxx/0?exp=1777166400000&sig=...",
        "file_id": "file_xxx"
      }
    ]
  }
}

4. 处理图片 URL

返回值可能是相对路径。展示或下载前请补齐 origin:
const DIMILINKS_ORIGIN = 'https://dimilinks.com'

export function normalizeImageUrl(url: string) {
  return new URL(url, DIMILINKS_ORIGIN).toString()
}

轮询建议

  • 每 2 到 3 秒查询一次任务状态。
  • 最长等待 8 到 10 分钟。
  • succeeded 后展示 result.data[].url
  • failed404 后停止轮询,并提示用户重试或调整输入。