创建图像
使用 CometAPI POST /v1/images/generations,通过兼容 OpenAI 的图像模型和模型专属控制项来创建图像。
官方参考
- 在使用
background、output_compression、streaming 或未来的 GPT 图像选项等模型专属控制项之前,请先阅读 OpenAI 图像生成指南。 - 当前参数列表请参考 OpenAI 创建图像参考。
先选择模型
- 对于带有
output_format、quality或background等控制项的文生图请求,请使用gpt-image-2这类 GPT 图像模型 - 当你明确需要该提供商时,使用
qwen-image,但请将n保持为 1 - 从模型页面选择当前可用的图像 model ID
安全的首次请求
- 从
gpt-image-2开始 - 将
size保持为1024x1024 - GPT 图像模型会在
b64_json中返回 base64 编码的图像数据;请将其解码后保存为图像文件 - 仅当你需要特定编码图像类型(如
jpeg)时再添加output_format - 在添加
background、output_compression或流式输出(Streaming)之前,请先查看 OpenAI 图像生成指南 - 在添加批量生成或风格调优之前,先使用一个 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 图像生成指南以了解最新的模型专属选项
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.