Skip to main content
POST
使用此路由,可通过 CometAPI 上兼容 OpenAI 的请求格式根据文本创建图像。

官方参考

先选择模型

  • 对于包含 gpt-image-2output_formatquality 等控件的文生图请求,请使用 GPT 图像模型,例如 background
  • 当需要透明背景或 gpt-image-2.5-sunburstgpt-image-2.5-flare 质量级别时,请使用 xhighmax
  • 当明确需要该提供商时,请使用 qwen-image,但将 n 保持为 1
  • 请从以下位置选择当前图像模型 ID: 模型页面

稳妥的首个请求

  • gpt-image-2 开始
  • size 保持为 1024x1024
  • GPT 图像模型会在 b64_json 中返回 base64 编码的图像数据;请将其解码以保存图像文件
  • 仅当需要特定的编码图像类型(例如 output_format)时,才添加 jpeg
  • 在添加批量生成或风格调优之前,先使用一个 Prompt 和一张输出图像

运行异步图像任务

当客户端倾向于采用提交并轮询流程,而不是保持一个 HTTP 连接持续打开时,请将 async: true 用于耗时较长的图像任务。创建请求会返回 data.task_id 轮询 检索图像生成任务 直到 data.statussuccessfailure async 字段是此路由的 CometAPI 扩展,并非 OpenAI 参数。OpenAI 为 GPT 图像模型记录了 streampartial_images。CometAPI 异步任务模式返回 JSON 任务元数据,并使用轮询。 对以下已记录的模型 ID 使用异步任务模式:gpt-image-2doubao-seedream-4-0-250828。对于其他图像模型,请使用同步生成或流式输出(Streaming),除非该模型已记录支持异步任务。 当请求同时包含 async: truestream: true 时,异步任务模式优先。创建请求将返回 JSON 任务元数据,而非 SSE 流。

模型专属请求行为

  • response_format 仅适用于 DALL·E 模型;GPT 图像模型会返回 base64 数据并忽略它
  • GPT 图像模型使用 GPT-only 控件,例如 output_formatqualitybackgroundoutput_compression
  • quality 在 GPT 图像模型上接受 lowmediumhighautogpt-image-2.5-sunburstgpt-image-2.5-flare 还接受 xhighmax
  • output_compressionoutput_formatwebpjpeg 时适用;对 png 无效
  • partial_images 仅当 streamtrue 时适用
  • 请参阅 OpenAI 图像生成指南,了解最新的模型专属选项
  • qwen-image 不支持 n > 1

生成透明背景

background 设置为 transparent,即可生成没有背景填充的孤立主体。gpt-image-2.5-sunburstgpt-image-2.5-flare 支持此功能。 透明效果需要使用带 alpha 通道的输出格式。将 output_format 设置为 pngwebp。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年9月11日