快速开始
1
创建 API 密钥
登录后打开账户中的 API Keys 页面,创建密钥,并妥善保存只显示一次的原始密钥。
2
检查模型和积分
调用 /api/v1/models 查看模型能力,再调用 /api/v1/credits 查看当前积分余额。
3
提交生成请求
调用 /api/v1/images/generations。长时间生成建议设置 async 为 true,并轮询返回的 poll_url。
接口
GET
/api/v1/modelsNo列出可用图像模型、支持的比例、画质和积分消耗。
GET
/api/v1/creditsBearer读取该 API 密钥所属用户的积分余额。
POST
/api/v1/images/generationsBearer根据提示词生成图像,可选上传参考图;设置 async=true 可创建异步任务。
GET
/api/v1/generations/:generationIdBearer获取生成日志以及该次生成保存的图像。
鉴权
除模型列表外,所有 v1 接口都需要在 Authorization 请求头中携带 API 密钥。原始密钥只会在创建时显示一次;服务器只保存哈希值。
Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx模型
模型接口会返回模型 ID、服务商、支持的画幅比例、支持的画质、参考图限制和每张图的积分消耗。
curl https://www.gptimagehub.com/api/v1/modelsGPT IMAGE 2
gpt-image-2API 模型 IDgpt-image-2
服务商openai
消耗1K: 8 | 2K: 10 | 4K: 12
默认选项auto, 1K
支持的画质1K, 2K, 4K
支持的比例auto, 1:1, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 5:4, 4:5, 21:9, 9:21, 2:1, 1:2, 3:1, 1:3
参考图最多张数: 16
请求字段
| 字段 | 值 | 备注 |
|---|---|---|
model | gpt-image-2 | 必须设置为此 API 模型 ID |
size | 1024x1024 | OpenAI 兼容的输出尺寸,例如 auto 或 1024x1024 |
quality | high | 可选画质: auto, low, medium, high |
n | 1 | 生成数量,范围 1 到 4 |
reference_image | @./reference.png | 仅用于 multipart/form-data;数量不能超过模型限制 |
JSON 调用
curl https://www.gptimagehub.com/api/v1/images/generations \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cinematic product photo with premium studio lighting",
"size": "1024x1024",
"quality": "high",
"n": 1
}'参考图调用
curl https://www.gptimagehub.com/api/v1/images/generations \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-F "model=gpt-image-2" \
-F "prompt=Use the reference image and render it as a premium studio product shot" \
-F "size=1024x1024" \
-F "quality=high" \
-F "n=1" \
-F "reference_image=@./reference.png"积分余额
积分接口会返回该 API 密钥所属用户的余额、账户类型和即将到期的积分信息。
curl https://www.gptimagehub.com/api/v1/credits \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"生成图像
图像生成接口默认等待生成完成。设置 async 为 true 可以立即获得 generation id,并通过 /api/v1/generations/:generationId 轮询结果。生成前会扣除积分;如果服务商生成失败或返回的图片少于请求数量,会自动退还相应积分。
JSON 请求
curl https://www.gptimagehub.com/api/v1/images/generations \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cinematic product photo of a transparent perfume bottle on black marble",
"size": "1024x1024",
"quality": "high",
"n": 1
}'异步任务
curl https://www.gptimagehub.com/api/v1/images/generations \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cinematic product photo with premium studio lighting",
"size": "1024x1024",
"quality": "high",
"n": 1,
"async": true
}'{
"object": "image_generation",
"id": "clx_generation_log_id",
"status": "queued",
"model": "gpt-image-2",
"aspect_ratio": "1:1",
"quality": "1K",
"created_at": "2026-04-30T08:00:00.000Z",
"images": [],
"usage": {
"credits": 0,
"credits_requested": 8
},
"poll_url": "https://www.gptimagehub.com/api/v1/generations/clx_generation_log_id"
}参考图请求
curl https://www.gptimagehub.com/api/v1/images/generations \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-F "model=gpt-image-2" \
-F "prompt=Use the reference image and render it as a premium studio product shot" \
-F "size=1024x1024" \
-F "quality=high" \
-F "n=1" \
-F "reference_image=@./reference.png"响应
{
"object": "image_generation",
"id": "clx_generation_log_id",
"status": "succeeded",
"model": "gpt-image-2",
"aspect_ratio": "1:1",
"quality": "1K",
"images": [
{
"id": "clx_image_id",
"object": "image",
"url": "https://cdn.example.com/generations/user/image.png",
"created_at": "2026-04-30T08:00:00.000Z"
}
],
"usage": {
"credits": 8
},
"balance": {
"credits": 112,
"account_type": "PRO",
"next_expiration": null
}
}查询生成记录
使用生成接口返回的 ID 查询保存的生成日志和图片 URL。API 密钥只能读取同一用户名下的生成记录。
curl https://www.gptimagehub.com/api/v1/generations/clx_generation_log_id \
-H "Authorization: Bearer gih_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"错误
{
"error": {
"message": "Invalid request body",
"code": "invalid_request"
}
}| HTTP | code | 说明 |
|---|---|---|
| 400 | invalid_request | 请求体或参数无效。 |
| 401 | missingApiKey | 缺少 Authorization 请求头。 |
| 401 | invalidApiKey | API 密钥不存在或已被撤销。 |
| 401 | expiredApiKey | API 密钥已过期。 |
| 402 | insufficientCredits | 账户积分不足。 |
| 404 | notFound | 请求的资源不存在。 |
| 500 | generationFailed | 图像生成失败。 |
限制
- 同步生成接口在生产环境最长可执行 800 秒。
- n 必须介于 1 和 4 之间。
- 参考图支持 PNG、JPG、JPEG 和 WebP。单个文件最大 50MB。
- 最大参考图数量由每个模型的 reference_image_limit 决定。
- 异步模式会返回 202 和 poll_url。当前版本暂不包含 webhook 或独立的 API 速率限制。