跳轉到主要內容
POST
使用此路由,以 CometAPI 上與 OpenAI 相容的請求格式從文字建立圖片。

官方參考資料

先選擇模型

  • 針對具備 gpt-image-2、output_format 或 quality 等控制項的文字轉圖片請求,請使用 background 等 GPT 圖片模型
  • 需要透明背景或 gpt-image-2.5-sunburst 與 gpt-image-2.5-flare 品質等級時,請使用 xhigh 或 max
  • 對於其他圖片模型系列,例如 Qwen-Image、Doubao Seedream 或 Grok Imagine,請使用相同的請求格式;先從 model 和 prompt 開始
  • 請從 模型頁面

選擇目前的圖片模型 ID。安全的第一個請求

  • 先使用 gpt-image-2
  • 將 size 保持為 1024x1024
  • GPT 圖片模型會在 b64_json 中傳回 base64 編碼的圖片資料;請將其解碼以儲存圖片檔案
  • 僅在需要特定的編碼圖片類型(例如 output_format)時,才加入 jpeg
  • 在加入批次生成或風格調整前,請先使用一個 Prompt 和一張輸出圖片

執行非同步圖片任務

當用戶端偏好提交後輪詢的流程,而非保持單一 HTTP 連線開啟時,請針對長時間執行的圖片工作使用 async: true。建立請求會傳回 data.task_id。 輪詢 擷取圖片生成任務 ,直到 data.status 為 success 或 failure。 async 欄位是此路由的 CometAPI 擴充功能,不是 OpenAI 參數。OpenAI 為 GPT 圖片模型記錄了 stream 和 partial_images。CometAPI 非同步任務模式會傳回 JSON 任務中繼資料,並使用輪詢。 請搭配以下已記錄的模型 ID 使用非同步任務模式:gpt-image-2 和 doubao-seedream-4-0-250828。對於其他圖片模型,除非該模型已記錄支援非同步任務,否則請使用同步生成或串流。 當請求同時包含 async: true 和 stream: true 時,非同步任務模式優先。建立請求會傳回 JSON 任務中繼資料,而非 SSE 串流。

模型專屬請求行為

  • response_format 僅適用於 DALL·E 模型;GPT 圖片模型會傳回 base64 資料並忽略它
  • GPT 圖片模型使用 GPT-only 控制項,例如 output_format、quality、background 和 output_compression
  • quality 可在 GPT 圖片模型上接受 low、medium、high 和 auto;gpt-image-2.5-sunburst 和 gpt-image-2.5-flare 也接受 xhigh 和 max
  • output_compression 當 output_format 為 webp 或 jpeg 時適用;對 png 無效
  • partial_images 僅在 stream 為 true 時適用
  • 請遵循 OpenAI 圖片生成指南,以取得最新的模型專屬選項
  • 其他圖片模型系列可能會在 url 而非 b64_json 中傳回圖片;請讀取每個結果項目所包含的欄位

產生透明背景

將 background 設為 transparent,即可產生沒有背景填色的獨立主體。gpt-image-2.5-sunburst 和 gpt-image-2.5-flare 支援此功能。 透明效果需要具備 Alpha 色版的輸出格式。請將 output_format 設為 png 或 webp。JPEG 沒有 Alpha 色版,因此使用 output_format: "jpeg" 提出透明背景請求會遭拒絕。 回應會在 b64_json 中傳回含有 Alpha 色版的 base64 圖片資料。請將其解碼以儲存檔案:
將 background 設為 opaque 可強制使用純色背景,或設為 auto 讓模型自行決定。回應會在頂層 background 欄位中回傳套用的值。
產生的圖片必須遵守供應商使用政策。請勿傳送非法、暴力、色情或侵害著作權的 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. GPT image models accept low, medium, high, and auto. gpt-image-2.5-sunburst and gpt-image-2.5-flare also accept xhigh and max. dall-e-3 accepts standard and hd. See the OpenAI image generation guide for the latest model-specific values.

範例:

"low"

background
enum<string>

Background mode for the generated image. Set transparent to generate an isolated subject with no background fill; this requires output_format set to png or webp, and returns an error with jpeg. Set opaque for a solid background, or auto to let the model decide. Supported on gpt-image-2.5-sunburst and gpt-image-2.5-flare.

可用選項:
transparent,
opaque,
auto
output_compression
integer
預設值:100

Compression level for the output image, from 0 to 100. Applies when output_format is webp or jpeg. Lower values produce smaller files with more compression artifacts.

必填範圍: 0 <= x <= 100
moderation
enum<string>
預設值:auto

Content moderation level for GPT image models. low is less restrictive; auto is the default.

可用選項:
low,
auto
partial_images
integer

Number of partial images to emit while a streaming response is in progress, from 0 to 3. Each partial image arrives as an image_generation.partial_image event before the final image_generation.completed event. Applies when stream is true.

必填範圍: 0 <= x <= 3
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.

最後修改於 2026年10月29日