Skip to main content
POST
使用這個路由,在 CometAPI 上以相容 OpenAI 的請求格式從文字建立圖片。

官方參考

先選擇模型

  • 針對文字轉圖片請求,使用如 gpt-image-2 之類的 GPT 圖片模型,並搭配 output_formatqualitybackground 等控制項
  • 當你特別需要該供應商時,使用 qwen-image,但請將 n 維持為 1
  • 模型頁面選擇目前可用的圖片 model ID

安全的第一個請求

  • 先從 gpt-image-2 開始
  • size 維持為 1024x1024
  • GPT 圖片模型會在 b64_json 中回傳 base64 編碼的圖片資料;請將其解碼以儲存圖片檔案
  • 只有在你需要特定編碼圖片類型(例如 jpeg)時,才加入 output_format
  • 在加入 backgroundoutput_compression 或串流之前,請先查看 OpenAI image generation guide
  • 在加入批次生成或風格微調之前,先使用單一 Prompt 和單一輸出圖片

執行非同步圖片任務

當用戶端偏好提交後輪詢的流程,而不是持續保持一條 HTTP 連線開啟時,可對長時間執行的圖片工作使用 async: true。建立請求會回傳 data.task_id 輪詢擷取圖片生成任務,直到 data.statussuccessfailure async 欄位是此路由的 CometAPI 擴充,不是 OpenAI 參數。OpenAI 對 GPT 圖片模型文件化了 streampartial_images。CometAPI 非同步任務模式會回傳 JSON 任務中繼資料,並使用輪詢。 請將非同步任務模式用於以下已文件化的 model ID:gpt-image-2doubao-seedream-4-0-250828。對於其他圖片模型,請使用同步生成或串流,除非該模型已有文件說明支援非同步任務。 當請求同時包含 async: truestream: true 時,非同步任務模式會優先生效。建立請求會回傳 JSON 任務中繼資料,而不是 SSE 串流。

模型專屬的請求行為

  • response_format 僅適用於 DALL·E 模型;GPT 圖片模型會回傳 base64 資料並忽略它
  • GPT 圖片模型使用 GPT 專屬控制項,例如 output_formatqualitybackgroundoutput_compression
  • 請遵循 OpenAI image generation guide 以取得最新的模型專屬選項
  • qwen-image 不支援 n > 1
生成的圖片必須符合供應商的使用政策。請勿傳送非法、暴力、色情或侵犯著作權的 Prompt。

授權

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

主體

application/json
model
string
預設值:gpt-image-2
必填

The image generation model to use. Choose a current model from the Models page.

prompt
string
必填

Text description of the image you want to generate.

範例:

"A paper boat floating on calm water at sunrise."

n
integer
預設值:1

Number of images to generate. Keep this at 1 for the broadest compatibility.

quality
string

Quality setting for models that support it. See the OpenAI image generation guide for the latest model-specific values.

size
string

Requested output size. Supported values depend on the selected model. See the OpenAI image generation guide for the latest model-specific ranges.

範例:

"1024x1024"

response_format
enum<string>

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
output_format
string

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"

stream
boolean
預設值:false

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.

async
boolean
預設值:false

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.

created
integer
必填

Unix timestamp for the completed generation.

data
object[]
必填
background
string

Background mode returned by models that expose it.

output_format
string

Encoded image type returned by GPT image models.

quality
string

Quality level returned by models that expose it.

size
string

Output size returned by models that expose it.

usage
object

Token usage details when returned by the selected model.