AI GPT ImageAI GPT Image
Image ModelsGPT Image

GPT Image 2 图生图

获取 API Keygpt-image-2-image-to-image

GPT Image 2 图生图 API 文档

使用 gpt-image-2-image-to-image 模型生成编辑后的图片或图生图结果

Overview

本文档说明如何使用 gpt-image-2-image-to-image 模型进行图片编辑和图生图。

集成流程分为两步:

  1. 创建生成任务
  2. 查询任务状态和结果

Authentication

所有 API 请求都需要在请求头中携带 Bearer Token:

Authorization: Bearer YOUR_API_KEY

获取 API Key:

  1. 打开 API Keys 页面
  2. 点击 Create API Key
  3. 在请求头中加入:Authorization: Bearer YOUR_API_KEY

1. 创建生成任务

API Information

  • URL: POST https://aigptimage.com/api/v1/jobs/createTask
  • Content-Type: application/json

Request Parameters

ParameterTypeRequiredDescription
modelstringYes对外模型 ID,必须精确传入 gpt-image-2-image-to-image
inputobjectYes输入参数对象

Model Parameter

model 参数用于指定对外公开的图片编辑模型。

PropertyValueDescription
Formatgpt-image-2-image-to-image精确的对外模型标识
Typestring必须传字符串
RequiredYes所有创建任务请求都必须提供

Note: model 的值必须完全匹配,并且必须使用本页展示的公开模型 ID。

input Object Parameters

prompt

  • Type: string
  • Required: Yes
  • Description: 描述如何编辑或转换源图片的文本提示词
  • Max Length: 20000 characters

image_urls

  • Type: string[]
  • Required: Yes
  • Description: 源图片 URL 列表
  • Constraints: 至少需要一个有效图片 URL

input_urls

  • Type: string[]
  • Required: No
  • Description: 对外 API 兼容接受的备用图片输入字段,传入后会透传给底层

image_input

  • Type: string[]
  • Required: No
  • Description: 对外 API 兼容接受的备用图片输入字段,传入后会透传给底层

aspect_ratio

  • Type: string
  • Required: No
  • Description: 输出图片比例
  • Common Options: auto, 1:1, 4:5, 3:4, 2:3, 16:9, 9:16

resolution

  • Type: string
  • Required: No
  • Description: 生成分辨率,同时也会影响积分消耗
  • Options: 1K, 2K, 4K
  • Default Value: 1K

quality

  • Type: string
  • Required: No
  • Description: 可选质量参数,会透传给底层图片模型

output_format

  • Type: string
  • Required: No
  • Description: 可选输出格式参数,会透传给底层图片模型

Request Example

{
  "model": "gpt-image-2-image-to-image",
  "input": {
    "prompt": "Turn this product photo into a premium studio advertisement with dramatic rim lighting",
    "image_urls": ["https://cdn.example.com/input.png"],
    "resolution": "1K"
  }
}

Response Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_xxxxxxxxxxxxx"
  }
}

Response Parameters

ParameterTypeDescription
codeinteger响应状态码,200 表示成功
msgstring响应消息
data.taskIdstring用于查询任务状态的任务 ID

2. 查询任务状态

API Information

  • URL: GET https://aigptimage.com/api/v1/jobs/recordInfo
  • Parameter: taskId(URL 查询参数)

Request Example

GET https://aigptimage.com/api/v1/jobs/recordInfo?taskId=task_xxxxxxxxxxxxx

Response Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_xxxxxxxxxxxxx",
    "model": "gpt-image-2-image-to-image",
    "state": "waiting",
    "param": "{\"model\":\"gpt-image-2-image-to-image\",\"input\":{\"prompt\":\"Turn this product photo into a premium studio advertisement with dramatic rim lighting\",\"image_urls\":[\"https://cdn.example.com/input.png\"],\"resolution\":\"1K\"}}",
    "resultJson": null,
    "failCode": null,
    "failMsg": null,
    "costTime": null,
    "completeTime": null,
    "createTime": 1757584164490
  }
}

Response Parameters

ParameterTypeDescription
codeinteger响应状态码,200 表示成功
msgstring响应消息
data.taskIdstring任务 ID
data.modelstring对外模型 ID
data.statestring任务状态:waitingsuccessfail
data.paramstring原始创建任务参数,JSON 字符串
data.resultJsonstring | null任务结果 JSON 字符串。图片任务成功时通常包含 resultUrls
data.failCodestring | null任务失败时的错误码
data.failMsgstring | null任务失败时的错误信息
data.costTimeinteger | null任务完成后的耗时,单位毫秒
data.completeTimeinteger | null完成时间戳,单位毫秒
data.createTimeinteger创建时间戳,单位毫秒

Success Result Structure

图片编辑任务成功时,resultJson 通常结构如下:

{
  "resultUrls": ["https://your-cdn.example.com/result-1.png"]
}

Usage Flow

  1. 先准备公开可访问且稳定可用的源图片 URL
  2. 调用 POST /api/v1/jobs/createTask
  3. 从响应中提取 taskId
  4. 轮询 GET /api/v1/jobs/recordInfo?taskId=...
  5. 成功后从 resultJson 中读取输出图片 URL

Notes

  • API 调用与网页端共用同一套积分余额和计费规则
  • 建议只传可信且稳定可访问的图片 URL
  • resolution 会影响输出尺寸和积分消耗

Error Codes

Status CodeDescription
200请求成功
400请求参数无效
401鉴权失败或 API key 无效
402积分不足
404任务或资源不存在
409活跃任务数超限或请求冲突
422参数校验失败
429请求超过限流
500服务内部错误