流式响应
Seedream-5.0-lite/4.5/4.0 支持流式输出模式。当您调用图片生成 API 并将 stream 设置为 true 时,服务器会在生成响应的过程中,通过 Server-Sent Events (SSE) 实时向客户端推送事件。本节内容介绍服务器会推送的各类事件。
image_generation.partial_succeeded
在流式响应模式下,当任意图片生成成功时返回。
参数说明
type string
此处应为 image_generation.partial_succeeded。
model string
本次请求使用的模型 ID,格式为<model-name>-<version>。
created integer
本次请求创建时间的 Unix 时间戳(秒)。
image_index integer
本次生图请求中,本次事件对应图片在请求中的序号。 从 0 开始累加,不管生图是否成功,即在 image_generation.partial_succeeded、image_generation.partial_failed 事件,均会自动累加 1。
url string
本次事件对应图片的下载 URL。当请求中配置字段 response_format 为 url 时返回。
b64_json string
本次事件对应图片的 Base64 编码。当请求中配置字段 response_format 为 b64_json 时返回。
size string
图像的宽高像素值,格式<width-px>x<height-px>,如 2048x2048。
image_generation.partial_failed
在流式返回模式下,当任意图片生成失败时返回该事件。
- 若失败原因为审核不通过:仍会继续请求下一个图片生成任务,即不影响同请求内其他图片的生成流程。
- 若失败原因为内部服务异常(500):不会继续请求下一个图片生成任务。
参数说明
type string
此处应为 image_generation.partial_failed。
model string
本次请求使用的模型 ID,格式为<model-name>-<version>。
created integer
本次请求创建时间的 Unix 时间戳(秒)。
image_index integer
本次生图请求中,本次事件对应图片在请求中的序号。 从 0 开始累加,不管图片是否生成成功,即在 image_generation.partial_succeeded、image_generation.partial_failed 事件,均会自动累加 1。
error object
本次生图请求中,本次事件对应的错误原因。
属性
error.codestring 请参见错误码。error.messagestring 错误提示信息
image_generation.completed
请求的所有图片(无论成功或失败)均处理完毕后返回,是该流式返回的最后一个响应事件。
参数说明
type string
此处应为 image_generation.completed。
model string
本次请求使用的模型 ID,格式为<model-name>-<version>。
created integer
本次请求创建时间的 Unix 时间戳(秒)。
tools array of object
本次请求,配置的模型调用工具。
属性
tools.typestring 配置的调用工具类型。web_search:联网搜索工具。
usage object
本次请求的用量信息。
属性
usage.generated_imagesinteger 模型成功生成的图片张数,不包含生成失败的图片。 仅对成功生成图片按张数进行计费。usage.input_imagesinteger(new,仅 Seedream 5.0 pro 返回) 输入模型的图片张数。usage.output_tokensinteger 模型生成的图片花费的 token 数量。 计算逻辑为:计算 sum(图片长×图片宽)/256,然后取整。usage.total_tokensinteger 本次请求消耗的总 token 数量。 当前不计算输入 token,故与 output_tokens 值一致。usage.tool_usageobject 使用工具的用量信息。usage.tool_usage.web_searchinteger 调用联网搜索工具次数,仅开启联网搜索时返回。
error
本次请求如发生错误,对应的错误信息。
参数说明
error object
本次请求错误,返回的错误信息。
属性
error.codestring 请参见错误码。error.messagestring 错误提示信息。
