鉴权与连接
- Base URL
https://backend:8000- Authorization
Authorization: Bearer YOUR_API_KEY- Content-Type
application/json- 模型名 (model)
gpt-image-2
接入协议
为什么选这个协议
适合需要提交任务并轮询状态的图像、视频、音频生成工作流。
接口地址
POST/v1/jobs
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
// REQUEST
{
"model": "gpt-image-2",
"input": {
"prompt": "white cat",
"reference_images": [
"https://example.com/reference.png",
{
"data_base64": "...",
"mime_type": "image/png"
}
],
"mask": "https://example.com/mask.png",
"size": "2752x1536",
"n": 1,
"response_format": "url",
"output_format": "jpeg",
"quality": "low",
"user": "user-123"
}
}// RESPONSE
{
"id": "job_example",
"object": "job",
"status": "processing",
"model": "gpt-image-2",
"created": 1710000000,
"request_id": "req_example"
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| prompt | string | Y |
| reference_images | array | N |
| mask | image | N |
| size | string | N |
| n | integer | N |
| response_format | enum | N |
| output_format | enum | N |
| quality | enum | N |
| user | string | 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",
"input": {
"prompt": "white cat",
"reference_images": [
"https://example.com/reference.png",
{
"data_base64": "...",
"mime_type": "image/png"
}
],
"mask": "https://example.com/mask.png",
"size": "2752x1536",
"n": 1,
"response_format": "url",
"output_format": "jpeg",
"quality": "low",
"user": "user-123"
}
}'
# 查询任务状态 cURL
# 将 job_example 替换为提交任务返回的 task_id
curl -X GET "https://backend:8000/v1/jobs/job_example" \
-H "Authorization: Bearer YOUR_API_KEY"