OpenAI 图像生成流式事件

2026-11-10 17:36 更新

图像生成流式事件

通过服务端发送事件实时流式传输图像生成和编辑结果。了解图像流式处理。

image_generation.partial_image

流式图像生成期间部分图像可用时发出。

结构定义

结构名称:ImageGenPartialImageEvent

  • b64_json: string

Base64编码的部分图像数据,可用于渲染图像。

  • background: "transparent" or "opaque" or "auto"

请求图像的背景设置。

  • "transparent"

  • "opaque"

  • "auto"

  • created_at: integer(Unix 时间戳)

事件创建时的Unix时间戳。

  • output_format: "png" or "webp" or "jpeg"

请求图像的输出格式。

  • "png"

  • "webp"

  • "jpeg"

  • partial_image_index: integer

部分图像的从0开始的索引,用于流式处理。

  • quality: "low" or "medium" or "high" or 3 more

请求图像的质量设置。

  • "low"

  • "medium"

  • "high"

  • "xhigh"

  • "max"

  • "auto"

  • size: string or "1024x1024" or "1024x1536" or "1536x1024" or "auto"

以WIDTHxHEIGHT表示的图像尺寸,例如1536x864。

  • string

  • "1024x1024" or "1024x1536" or "1536x1024" or "auto"

以WIDTHxHEIGHT表示的图像尺寸,例如1536x864。

  • "1024x1024"

  • "1024x1536"

  • "1536x1024"

  • "auto"

  • type: "image_generation.partial_image"

事件类型,固定为image_generation.partial_image。

  • "image_generation.partial_image"

示例

中文说明:以下为原文配置、命令或事件示例,字段名、枚举、标识符及数值保留。

{
  "type": "image_generation.partial_image",
  "b64_json": "...",
  "created_at": 1620000000,
  "size": "1024x1024",
  "quality": "high",
  "background": "transparent",
  "output_format": "png",
  "partial_image_index": 0
}

image_generation.completed

图像生成完成且最终图像可用时发出。

结构定义

结构名称:ImageGenCompletedEvent

  • b64_json: string

经过Base64编码的图像数据,可用于渲染为图像。

  • background: "transparent" or "opaque" or "auto"

生成图像的背景设置。

  • "transparent"

  • "opaque"

  • "auto"

  • created_at: integer(Unix 时间戳)

事件创建时的Unix时间戳。

  • output_format: "png" or "webp" or "jpeg"

生成图像的输出格式。

  • "png"

  • "webp"

  • "jpeg"

  • quality: "low" or "medium" or "high" or 3 more

生成图像的质量设置。

  • "low"

  • "medium"

  • "high"

  • "xhigh"

  • "max"

  • "auto"

  • size: string or "1024x1024" or "1024x1536" or "1536x1024" or "auto"

以WIDTHxHEIGHT表示的图像尺寸,例如1536x864。

  • string

  • "1024x1024" or "1024x1536" or "1536x1024" or "auto"

以WIDTHxHEIGHT表示的图像尺寸,例如1536x864。

  • "1024x1024"

  • "1024x1536"

  • "1536x1024"

  • "auto"

  • type: "image_generation.completed"

事件类型,固定为image_generation.completed。

  • "image_generation.completed"

  • usage: object { input_tokens, input_tokens_details, output_tokens, total_tokens }

图像生成的词元用量信息,仅GPT图像模型提供。

  • input_tokens: integer

输入提示词中的词元数量,包括图像与文本词元。

  • input_tokens_details: object { image_tokens, text_tokens }

图像生成的输入词元详情。

  • image_tokens: integer

输入提示词中的图像词元数量。

  • text_tokens: integer

输入提示词中的文本词元数量。

  • output_tokens: integer

输出图像中的图像词元数量。

  • total_tokens: integer

图像生成使用的词元总数,包括图像与文本词元。

  • safety_identifier: optional string or null

用于安全监控和滥用检测的有效安全标识。采用请求中的非空safety_identifier;若其省略、为null或为空,则使用已弃用的user值。

示例

中文说明:以下为原文配置、命令或事件示例,字段名、枚举、标识符及数值保留。

{
  "type": "image_generation.completed",
  "b64_json": "...",
  "created_at": 1620000000,
  "size": "1024x1024",
  "quality": "high",
  "background": "transparent",
  "output_format": "png",
  "usage": {
    "total_tokens": 100,
    "input_tokens": 50,
    "output_tokens": 50,
    "input_tokens_details": {
      "text_tokens": 10,
      "image_tokens": 40
    }
  }
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号