建立圖片
使用 CometAPI POST /v1/images/generations,以相容 OpenAI 的圖片模型與模型專屬控制項來建立圖片。
官方參考
- 在你依賴
background、output_compression、串流或未來的 GPT 圖片選項等模型專屬控制項之前,請先閱讀 OpenAI image generation guide - 目前的參數清單請參考 OpenAI Create image reference
先選擇模型
- 針對文字轉圖片請求,使用如
gpt-image-2之類的 GPT 圖片模型,並搭配output_format、quality或background等控制項 - 當你特別需要該供應商時,使用
qwen-image,但請將n維持為 1 - 從模型頁面選擇目前可用的圖片 model ID
安全的第一個請求
- 先從
gpt-image-2開始 - 將
size維持為1024x1024 - GPT 圖片模型會在
b64_json中回傳 base64 編碼的圖片資料;請將其解碼以儲存圖片檔案 - 只有在你需要特定編碼圖片類型(例如
jpeg)時,才加入output_format - 在加入
background、output_compression或串流之前,請先查看 OpenAI image generation guide - 在加入批次生成或風格微調之前,先使用單一 Prompt 和單一輸出圖片
執行非同步圖片任務
當用戶端偏好提交後輪詢的流程,而不是持續保持一條 HTTP 連線開啟時,可對長時間執行的圖片工作使用async: true。建立請求會回傳 data.task_id。
輪詢擷取圖片生成任務,直到 data.status 為 success 或 failure。
async 欄位是此路由的 CometAPI 擴充,不是 OpenAI 參數。OpenAI 對 GPT 圖片模型文件化了 stream 與 partial_images。CometAPI 非同步任務模式會回傳 JSON 任務中繼資料,並使用輪詢。
請將非同步任務模式用於以下已文件化的 model ID:gpt-image-2 與 doubao-seedream-4-0-250828。對於其他圖片模型,請使用同步生成或串流,除非該模型已有文件說明支援非同步任務。
當請求同時包含 async: true 與 stream: true 時,非同步任務模式會優先生效。建立請求會回傳 JSON 任務中繼資料,而不是 SSE 串流。
模型專屬的請求行為
response_format僅適用於 DALL·E 模型;GPT 圖片模型會回傳 base64 資料並忽略它- GPT 圖片模型使用 GPT 專屬控制項,例如
output_format、quality、background和output_compression - 請遵循 OpenAI image generation guide 以取得最新的模型專屬選項
qwen-image不支援n > 1
授權
Bearer token authentication. Use your CometAPI key.
主體
The image generation model to use. Choose a current model from the Models page.
Text description of the image you want to generate.
"A paper boat floating on calm water at sunrise."
Number of images to generate. Keep this at 1 for the broadest compatibility.
Quality setting for models that support it. See the OpenAI image generation guide for the latest model-specific values.
Requested output size. Supported values depend on the selected model. See the OpenAI image generation guide for the latest model-specific ranges.
"1024x1024"
The response container for dall-e-2 and dall-e-3. This parameter is not supported for GPT image models, which return base64-encoded image data.
url, b64_json The encoded image type for GPT image model results, such as png, jpeg, or webp. See the OpenAI image generation guide for current GPT image output controls.
"jpeg"
Set this to true to receive server-sent image generation events instead of waiting for the completed JSON response. Streaming responses use text/event-stream and can include final events such as image_generation.completed. When stream and async are both true, async task mode takes precedence and the create request returns JSON instead of a streaming image response.
CometAPI asynchronous task mode. Set this to true to return immediately with data.task_id, then poll GET /v1/images/generations/{task_id} for the final image data. Documented model IDs for this mode: gpt-image-2 and doubao-seedream-4-0-250828. This is a CometAPI extension, not an OpenAI parameter. When async and stream are both true, async takes precedence and returns JSON task metadata instead of an SSE stream.
回應
Image generation result. Synchronous requests return completed image data. Async requests return a task response with data.task_id.
- Completed image response
- Async task response
Unix timestamp for the completed generation.
Background mode returned by models that expose it.
Encoded image type returned by GPT image models.
Quality level returned by models that expose it.
Output size returned by models that expose it.
Token usage details when returned by the selected model.