> ## Documentation Index
> Fetch the complete documentation index at: https://docs.powertokens.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 流式响应

> Seedream-5.0/4.5/4.0 支持流式输出模式。当您调用图片生成 API 并将 **stream** 设置为 `true` 时，服务器会在生成响应的过程中，通过 Server-Sent Events（SSE）实时向客户端推送事件。本节内容介绍服务器会推送的各类事件。



## OpenAPI

````yaml api-reference/zh-Hans/zmodelImage/byteplus/seedream/seedream-streaming.json POST /byteplus/api/v3/images/generations
openapi: 3.0.1
info:
  title: 流式响应
  version: 1.0.0
  description: >-
    Seedream-5.0/4.5/4.0 支持流式输出模式。当您调用图片生成 API 并将 **stream** 设置为 `true`
    时，服务器会在生成响应的过程中，通过 Server-Sent Events（SSE）实时向客户端推送事件。本节内容介绍服务器会推送的各类事件。
  license:
    name: Project License
    url: https://github.com/QuantumNous/new-api/blob/main/LICENSE
servers:
  - url: https://api.powertokens.ai
    description: Baze API 服务地址
security: []
tags:
  - name: Seedream API Compat
    description: Seedream 流式响应接口
paths:
  /byteplus/api/v3/images/generations:
    post:
      tags:
        - Seedream API Compat
      summary: 流式响应事件
      description: >-
        Seedream-5.0/4.5/4.0 支持流式输出模式。当您调用图片生成 API 并将 **stream** 设置为 `true`
        时，服务器会在生成响应的过程中，通过 Server-Sent Events（SSE）实时向客户端推送事件。本节内容介绍服务器会推送的各类事件。
      operationId: seedreamStreaming
      responses:
        '200':
          description: >-
            SSE 流式响应。响应类型为 `text/event-stream`。


            ## image_generation.partial_succeeded


            > 当前仅 Seedream-5.0/4.5/4.0 支持流式响应。


            在流式响应模式下，当任意图片生成成功时返回该事件。


            **type** `string`


            此处应为 `image_generation.partial_succeeded`。


            ---


            **model** `string`


            本次请求使用的模型 ID，格式为 `<模型名称>-<版本>`。


            ---


            **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`


            图像的宽高像素值，格式 `<宽像素>×<高像素>`，如 `2048×2048`。


            ---


            ### 返回示例


            ```Shell

            {
              "type": "image_generation.partial_succeeded",
              "model": "doubao-seedream-5-0-260128",
              "created": 1589478378,
              "image_index": 0,
              "url": "https://...",
              "size": "2048×2048"
            }

            ```


            ---


            ## image_generation.partial_failed


            > 当前仅 Seedream-5.0/4.5/4.0 支持流式响应。


            在流式返回模式下，当任意图片生成失败时返回该事件。


            - 若失败原因为审核不通过：仍会继续请求下一个图片生成任务，即不影响同请求内其他图片的生成流程。

            - 若失败原因为内部服务异常（500）：不会继续请求下一个图片生成任务。


            **type** `string`


            此处应为 `image_generation.partial_failed`。


            ---


            **model** `string`


            本次请求使用的模型 ID，格式为 `<模型名称>-<版本>`。


            ---


            **created** `integer`


            本次请求创建时间的 Unix 时间戳（秒）。


            ---


            **image_index** `integer`


            本次生图请求中，本次事件对应图片在请求中的序号。

            从 `0` 开始累加，不管图片是否生成成功，即在
            `image_generation.partial_succeeded`、`image_generation.partial_failed`
            事件，均会自动累加 1。


            ---


            **error** `object`


            本次生图请求中，本次事件对应的错误原因。


            error. **code** `string`


            错误码。


            error. **message** `string`


            错误提示信息。


            ### 返回示例


            ```Shell

            {
              "type": "image_generation.partial_failed",
              "model": "doubao-seedream-5-0-260128",
              "created": 1589478378,
              "image_index": 2,
              "error": {
                  "code":"OutputImageSensitiveContentDetected",
                  "message":"The request failed because the output image may contain sensitive information."
              }
            }

            ```


            ---


            ## image_generation.completed


            > 当前仅 Seedream-5.0/4.5/4.0 支持流式响应。


            请求的所有图片（无论成功或失败）均处理完毕后返回，是该流式返回的最后一个响应事件。


            **type** `string`


            此处应为 `image_generation.completed`。


            ---


            **model** `string`


            本次请求使用的模型 ID，格式为 `<模型名称>-<版本>`。


            ---


            **created** `integer`


            本次请求创建时间的 Unix 时间戳（秒）。


            ---


            **tools** `array of object`


            本次请求配置的模型调用工具。


            tools. **type** `string`


            配置的调用工具类型。


            - web_search：联网搜索工具。


            ---


            **usage** `object`


            本次请求的用量信息。


            usage. **generated_images** `integer`


            模型成功生成的图片张数，不包含生成失败的图片。仅对成功生成图片按张数进行计费。


            usage. **output_tokens** `integer`


            模型生成的图片花费的 token 数量。计算逻辑为：计算 `sum(图片长*图片宽)/256` ，然后取整。


            usage. **total_tokens** `integer`


            本次请求消耗的总 token 数量。当前不计算输入 token，故与 **output_tokens** 值一致。


            usage. **tool_usage** `object`


            使用工具的用量信息。


            usage.tool_usage. **web_search** `integer`


            调用联网搜索工具次数，仅开启联网搜索时返回。


            ### 返回示例


            ```Shell

            {
              "type": "image_generation.completed",
              "model": "doubao-seedream-5-0-260128",
              "created": 1589478378,
              "tools": [
                     {
                         "type": "web_search",
                     }
                 ],
              "usage": {
                  "generated_images": 2,
                  "output_tokens": xx,
                  "total_tokens": xx,
                  "tool_usage":{
                    "web_search":1
                }
              }
            }

            ```


            ---


            ## error


            本次请求如发生错误，对应的错误信息。


            **error** `object`


            本次请求错误返回的错误信息。


            error. **code** `string`


            错误码。


            error. **message** `string`


            错误提示信息。


            ### 返回示例


            ```Shell

            "error": {
              "code":"BadRequest",
              "message":"The request failed because it is missing one or multiple required parameters. Request ID: {id}"
            }

            ```
          content:
            text/event-stream:
              schema:
                type: string
                description: ''
              examples:
                seedream-5.0-流式输出:
                  summary: seedream-5.0-流式输出
                  value: >
                    event: image_generation.partial_succeeded

                    data:
                    {"type":"image_generation.partial_succeeded","model":"seedream-5-0-260128","created":1757396757,"image_index":0,"url":"https://...","size":"2496x1664"}


                    event: image_generation.partial_succeeded

                    data:
                    {"type":"image_generation.partial_succeeded","model":"seedream-5-0-260128","created":1757396785,"image_index":1,"url":"https://...","size":"2496x1664"}


                    event: image_generation.partial_succeeded

                    data:
                    {"type":"image_generation.partial_succeeded","model":"seedream-5-0-260128","created":1757396825,"image_index":2,"url":"https://...","size":"2496x1664"}


                    event: image_generation.completed

                    data:
                    {"type":"image_generation.completed","model":"seedream-5-0-260128","created":1757396825,"usage":{"generated_images":3,"output_tokens":48672,"total_tokens":48672}}


                    data: [DONE]

````