快速開始
1
建立 API 金鑰
登入後開啟帳戶中的 API 金鑰頁面,建立金鑰,並妥善保存只顯示一次的原始金鑰。
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/modelsZ-Image Turbo
z-image-turboAPI 模型 IDz-image-turbo
服務商alibaba
消耗15
預設選項auto, 1K
支援的畫質1K, 2K
支援的比例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
參考圖不支援
請求欄位
| 欄位 | 值 | 備註 |
|---|---|---|
model | z-image-turbo | 必須設定為此 API 模型 ID |
size | 1024x1024 | OpenAI 相容的輸出尺寸,例如 auto 或 1024x1024 |
quality | high | 可選畫質: auto, low, medium, high |
n | 1 | 生成數量,範圍 1 到 4 |
reference_image | - | 僅用於 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": "z-image-turbo",
"prompt": "A cinematic product photo with premium studio lighting",
"size": "1024x1024",
"quality": "high",
"n": 1
}'點數餘額
點數端點會傳回該 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" \
-H "Idempotency-Key: order-1042-hero-image" \
-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": 7
},
"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": 7
},
"balance": {
"credits": 113,
"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": "invalidRequest"
}
}| HTTP | code | 說明 |
|---|---|---|
| 400 | invalidRequest | 請求體或參數無效。 |
| 401 | missingApiKey | 缺少 Authorization 請求標頭。 |
| 401 | invalidApiKey | API 金鑰不存在或已被撤銷。 |
| 401 | expiredApiKey | API 金鑰已過期。 |
| 401 | emailUnverified | 帳號電子郵件尚未驗證。請透過我們寄送的電子郵件進行驗證後再重試。 |
| 402 | insufficientCredits | 帳戶點數不足。 |
| 404 | notFound | 請求的資源不存在。 |
| 429 | rateLimited | 請求過多。請等待 Retry-After 標頭中指定的秒數後再重試。 |
| 429 | freeTierLimited | 僅持有免費註冊額度的帳號每小時最多可生成 10 張圖片。 |
| 500 | generationFailed | 圖像生成失敗。 |
| 503 | serviceUnavailable | 服務暫時無法使用。請於 Retry-After 標頭指定的時間後重試。 |
限制
- 在正式環境中,同步生成最長可執行 800 秒。
- n 必須介於 1 到 4 之間。
- 參考圖片支援 PNG、JPG、JPEG 和 WebP。包含所有參考圖片在內的整個請求大小必須低於 4.5MB(圖片總計請保持在 4MB 以下)。過大的請求會在抵達 API 之前被託管平台以純文字 413 拒絕,因此請先調整圖片大小或進行壓縮。
- 參考圖片的數量上限由各模型的 reference_image_limit 定義。
- 速率限制:每個 API key 每分鐘 60 次生成請求,每個 IP 位址每分鐘 120 次。每個回應皆帶有 RateLimit-Limit、RateLimit-Remaining 與 RateLimit-Reset 標頭;429 回應亦會帶有 Retry-After。
- 若要安全地重試生成,請傳送 Idempotency-Key 標頭(最多 120 個字元)。使用相同的 API key 重複傳送相同的 key 將回傳原先的生成結果,而不會再次計費。
- 非同步模式會回傳 202 與 poll_url。目前尚未支援 Webhook。