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

官方参考

先选择模型

  • 对于带有 output_formatqualitybackground 等控制项的文生图请求,请使用 gpt-image-2 这类 GPT 图像模型
  • 当你明确需要该提供商时,使用 qwen-image,但请将 n 保持为 1
  • 模型页面选择当前可用的图像 model ID

安全的首次请求

  • gpt-image-2 开始
  • size 保持为 1024x1024
  • GPT 图像模型会在 b64_json 中返回 base64 编码的图像数据;请将其解码后保存为图像文件
  • 仅当你需要特定编码图像类型(如 jpeg)时再添加 output_format
  • 在添加 backgroundoutput_compression 或流式输出(Streaming)之前,请先查看 OpenAI 图像生成指南
  • 在添加批量生成或风格调优之前,先使用一个 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 图像生成指南以了解最新的模型专属选项
  • 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.