创建图像
使用 CometAPI POST /v1/images/generations 通过兼容 OpenAI 的图像模型和模型专属控件创建图像。
官方参考
- 请阅读 OpenAI 图像生成指南 然后再依赖
background、output_compression、流式输出(Streaming)或未来的 GPT 图像选项等模型专属控件。 - 请使用 OpenAI 创建图像参考 查看当前参数列表。
先选择模型
- 对于包含
gpt-image-2、output_format或quality等控件的文生图请求,请使用 GPT 图像模型,例如background - 当需要透明背景或
gpt-image-2.5-sunburst和gpt-image-2.5-flare质量级别时,请使用xhigh或max - 当明确需要该提供商时,请使用
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.status 为 success 或 failure。
async 字段是此路由的 CometAPI 扩展,并非 OpenAI 参数。OpenAI 为 GPT 图像模型记录了 stream 和 partial_images。CometAPI 异步任务模式返回 JSON 任务元数据,并使用轮询。
对以下已记录的模型 ID 使用异步任务模式:gpt-image-2 和 doubao-seedream-4-0-250828。对于其他图像模型,请使用同步生成或流式输出(Streaming),除非该模型已记录支持异步任务。
当请求同时包含 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和maxoutput_compression当output_format为webp或jpeg时适用;对png无效partial_images仅当stream为true时适用- 请参阅 OpenAI 图像生成指南,了解最新的模型专属选项
qwen-image不支持n > 1
生成透明背景
将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 字段中回显应用的值。
授权
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. 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 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 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 <= 100Content moderation level for GPT image models. low is less restrictive; auto is the default.
low, auto 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 <= 3Requested 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.