Image ModelsGPT Image
GPT Image 2 文生图
获取 API Keygpt-image-2-text-to-image
GPT Image 2 文生图 API 文档
使用
gpt-image-2-text-to-image模型生成图片内容
Overview
本文档说明如何使用 gpt-image-2-text-to-image 模型进行图片生成。
集成流程分为两步:
- 创建生成任务
- 查询任务状态和结果
Authentication
所有 API 请求都需要在请求头中携带 Bearer Token:
Authorization: Bearer YOUR_API_KEY获取 API Key:
- 打开 API Keys 页面
- 点击
Create API Key - 在请求头中加入:
Authorization: Bearer YOUR_API_KEY
1. 创建生成任务
API Information
- URL:
POST https://aigptimage.com/api/v1/jobs/createTask - Content-Type:
application/json
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | 对外模型 ID,必须精确传入 gpt-image-2-text-to-image |
input | object | Yes | 输入参数对象 |
Model Parameter
model 参数用于指定对外公开模型。
| Property | Value | Description |
|---|---|---|
| Format | gpt-image-2-text-to-image | 精确的对外模型标识 |
| Type | string | 必须传字符串 |
| Required | Yes | 所有创建任务请求都必须提供 |
Note:
model的值必须完全匹配,并且必须使用本页展示的公开模型 ID。
input Object Parameters
prompt
- Type:
string - Required: Yes
- Description: 用于描述要生成图片的文本提示词
- Max Length: 20000 characters
aspect_ratio
- Type:
string - Required: No
- Description: 输出图片比例
- Common Options:
auto,1:1,4:5,3:4,2:3,16:9,9:16,21:9 - Default Value: 由底层模型默认决定
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-text-to-image",
"input": {
"prompt": "A cinematic product photo of a transparent speaker on a reflective black table",
"aspect_ratio": "1:1",
"resolution": "1K"
}
}Response Example
{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_xxxxxxxxxxxxx"
}
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
code | integer | 响应状态码,200 表示成功 |
msg | string | 响应消息 |
data.taskId | string | 用于查询任务状态的任务 ID |
真实示例
创建任务:
curl -X POST "https://aigptimage.com/api/v1/jobs/createTask" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "X-Request-ID: xxxxxxxxxxxx" \
-d '{
"model": "gpt-image-2-text-to-image",
"input": {
"prompt": "Generate an analysis and usage instruction diagram for the equipment name narrow-grip pulldown machine. Requirements: 3:4 aspect ratio, 4k resolution."
}
}'创建任务响应:
{
"code": 200,
"msg": "success",
"data": {
"taskId": "3ebe82c2-3abc-4015-9608-901baca54948"
}
}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_xxxxxxxxxxxxxResponse Example
{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_xxxxxxxxxxxxx",
"model": "gpt-image-2-text-to-image",
"state": "waiting",
"param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"A cinematic product photo of a transparent speaker on a reflective black table\",\"aspect_ratio\":\"1:1\",\"resolution\":\"1K\"}}",
"resultJson": null,
"failCode": null,
"failMsg": null,
"costTime": null,
"completeTime": null,
"createTime": 1757584164490
}
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
code | integer | 响应状态码,200 表示成功 |
msg | string | 响应消息 |
data.taskId | string | 任务 ID |
data.model | string | 对外模型 ID |
data.state | string | 任务状态:waiting、success、fail |
data.param | string | 原始创建任务参数,JSON 字符串 |
data.resultJson | string | null | 任务结果 JSON 字符串。图片任务成功时通常包含 resultUrls |
data.failCode | string | null | 任务失败时的错误码 |
data.failMsg | string | null | 任务失败时的错误信息 |
data.costTime | integer | null | 任务完成后的耗时,单位毫秒 |
data.completeTime | integer | null | 完成时间戳,单位毫秒 |
data.createTime | integer | 创建时间戳,单位毫秒 |
Success Result Structure
图片生成任务成功时,resultJson 通常结构如下:
{
"resultUrls": ["https://your-cdn.example.com/result-1.png"]
}真实查询示例
查询任务:
curl "https://aigptimage.com/api/v1/jobs/recordInfo?taskId=3ebe82c2-3abc-4015-9608-901baca54948" \
-H "Authorization: Bearer sk-xxxxxxxxxx"查询任务响应:
{
"code": 200,
"msg": "success",
"data": {
"taskId": "3ebe82c2-3abc-4015-9608-901baca54948",
"model": "gpt-image-2-text-to-image",
"state": "success",
"param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"Generate an analysis and usage instruction diagram for the equipment name narrow-grip pulldown machine. Requirements: 3:4 aspect ratio, 4k resolution.\"}}",
"resultJson": "{\"resultUrls\":[\"https://cdn.aigptimage.com/generation/image/3ebe82c2-3abc-4015-9608-901baca54948/1.png\"]}",
"failCode": null,
"failMsg": null,
"costTime": 59699,
"completeTime": 1777467267840,
"createTime": 1777467208141
}
}Usage Flow
- 调用
POST /api/v1/jobs/createTask - 从响应中提取
taskId - 轮询
GET /api/v1/jobs/recordInfo?taskId=... - 等待
state变成success或fail - 成功后从
resultJson中读取输出图片 URL
Notes
- API 调用与网页端共用同一套积分余额和计费规则
- 限流额度取决于 API key 所属等级
resolution会影响输出尺寸和积分消耗
Error Codes
| Status Code | Description |
|---|---|
200 | 请求成功 |
400 | 请求参数无效 |
401 | 鉴权失败或 API key 无效 |
402 | 积分不足 |
404 | 任务或资源不存在 |
409 | 活跃任务数超限或请求冲突 |
422 | 参数校验失败 |
429 | 请求超过限流 |
500 | 服务内部错误 |