鉴权与连接
- Base URL
https://backend:8000- Authorization
Authorization: Bearer YOUR_API_KEY- Content-Type
application/json- 模型名 (model)
gpt-image-2/text-to-image
接入协议
为什么选这个协议
适合已有 OpenAI Images 图片生成接口代码,且希望同步拿到图片结果的用户。
接口地址
POST/v1/images/generations
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
// REQUEST
{
"model": "gpt-image-2/text-to-image",
"prompt": "生成一张产品海报,白色背景,商业摄影风格",
"size": "2752x1536",
"response_format": "url"
}// RESPONSE
{
"created": 1710000000,
"data": [
{
"url": "https://example.com/output.png"
}
]
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| model | string | Y |
| prompt | string | Y |
| size | string | Y |
| response_format | string | Y |
// RESPONSE SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| created | integer | Y |
| data | array | Y |
| data[] | object | Y |
| data[].url | string | Y |
代码示例
cURLrequest.sh
curl -X POST "https://backend:8000/v1/images/generations" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-image-2/text-to-image",
"prompt": "生成一张产品海报,白色背景,商业摄影风格",
"size": "2752x1536",
"response_format": "url"
}'为什么选这个协议
适合需要提交任务并轮询状态的图像、视频、音频生成工作流。
接口地址
POST/v1/jobs
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
// REQUEST
{
"model": "gpt-image-2/text-to-image",
"input": {
"prompt": "生成一张产品海报,白色背景,商业摄影风格",
"size": "2752x1536",
"quality": "medium",
"output_format": "png",
"response_format": "url",
"background": "auto",
"n": 1,
"user": "user-123",
"resolution": "1K"
}
}// RESPONSE
{
"id": "job_example",
"object": "job",
"status": "processing",
"model": "gpt-image-2/text-to-image",
"created": 1710000000,
"request_id": "req_example"
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| prompt | string | Y |
| size | string | N |
| quality | enum | N |
| output_format | enum | N |
| response_format | enum | N |
| background | enum | N |
| n | integer | N |
| user | string | N |
| resolution | enum | N |
// RESPONSE SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| id | string | N |
| status | enum | N |
| model | string | N |
| output.images[].url | image | N |
| output.images[].mime_type | string | N |
代码示例
cURLrequest.sh
curl -X POST "https://backend:8000/v1/jobs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-image-2/text-to-image",
"input": {
"prompt": "生成一张产品海报,白色背景,商业摄影风格",
"size": "2752x1536",
"quality": "medium",
"output_format": "png",
"response_format": "url",
"background": "auto",
"n": 1,
"user": "user-123",
"resolution": "1K"
}
}'
# 查询任务状态 cURL
# 将 job_example 替换为提交任务返回的 task_id
curl -X GET "https://backend:8000/v1/jobs/job_example" \
-H "Authorization: Bearer YOUR_API_KEY"