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

# Seedream 图片生成接口

> 兼容 Seedream 官方协议的图片生成接口，支持文生图、图生图、组图与图层分解

此接口与 Seedream 官方协议一致，在 OpenAI Images 协议基础上扩展了 Seedream 专属参数，支持参考图输入、组图生成与图层分解等能力。

## 功能特性

* 兼容 OpenAI Images 协议基础参数（`prompt`、`size`、`output_format` 等）
* 支持图生图，通过 `image` 传入参考图片（URL 或 Base64）
* 支持组图生成 `sequential_image_generation`，基于输入内容生成一组内容关联的图片，可配置最大数量
* 支持图层分解 `layer_decomposition`，返回拆分后的图层与边界框信息
* 支持提示词优化 `optimize_prompt_options`（`standard` / `fast` 两种模式）
* 支持 `1K`、`2K` 等分辨率档位与 `1024x1024` 等具体尺寸
* 支持水印控制 `watermark`

## 认证方式

在请求头中携带 `Authorization` 字段，格式为 `Bearer YOUR_API_KEY`。

## 支持的图片模型

seedream 系列模型。

## 快速示例

<CodeGroup>
  ```python Python theme={null}
  import requests

  url = "https://api.haitoken.ai/v1/images/generations"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json"
  }
  data = {
      "model": "dola-seedream-5.0-pro",
      "prompt": "一只橘猫戴着宇航员头盔漂浮在太空中，背景是地球",
      "size": "2K",
      "watermark": False,
      "response_format": "url"
  }

  response = requests.post(url, json=data, headers=headers)
  print(response.json())
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.haitoken.ai/v1/images/generations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'dola-seedream-5.0-pro',
      prompt: '一只橘猫戴着宇航员头盔漂浮在太空中，背景是地球',
      size: '2K',
      watermark: false,
      response_format: 'url'
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```curl cURL theme={null}
  curl -X POST 'https://api.haitoken.ai/v1/images/generations' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "dola-seedream-5.0-pro",
      "prompt": "一只橘猫戴着宇航员头盔漂浮在太空中，背景是地球",
      "size": "2K",
      "watermark": false,
      "response_format": "url"
    }'
  ```
</CodeGroup>

生成成功后返回图片数据：

```json theme={null}
{
  "created": 1787875200,
  "model": "dola-seedream-5.0-pro",
  "data": [
    {
      "url": "https://example.com/images/generated-1.png",
      "size": "2048x2048"
    }
  ],
  "usage": {
    "output_tokens": 8320,
    "total_tokens": 8320,
    "generated_images": 1,
    "input_images": 0
  }
}
```

## 下一步

* 查看 [OpenAI 图片生成接口](/docs/zh/api-reference/images/openai/generation) 了解基础协议参数
* 查看 [OpenAI 图片编辑接口](/docs/zh/api-reference/images/openai/edit) 编辑已有图片
* 查看 [模型列表](/docs/zh/api-reference/models/list-models) 了解可用的图片模型


## OpenAPI

````yaml zh/api-reference/images/seedream/generation/openapi.json POST /v1/images/generations
openapi: 3.0.1
info:
  title: 默认模块
  description: ''
  version: 1.0.0
servers: []
security: []
tags: []
paths:
  /v1/images/generations:
    post:
      tags: []
      summary: seedream图片接口
      parameters:
        - name: Authorization
          in: header
          description: API Key token (Bearer sk-xxx)
          required: true
          example: 'Bearer '
          schema:
            type: string
        - name: Content-Type
          in: header
          description: ''
          example: application/json
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              description: ''
              type: object
              properties:
                model:
                  type: string
                  description: 模型名称
                prompt:
                  type: string
                  description: 提示词
                image:
                  type: object
                  properties: {}
                  description: 参考图片，URL 或 Base64 字符串（Seedream 扩展参数，用于图生图）
                layer_decomposition:
                  type: boolean
                  description: 是否进行图层分解： true 分解，false 不分解(default)
                size:
                  type: string
                  description: 生成图片尺寸，如 "1024x1024"、"1K“、“2K”等
                optimize_prompt_options:
                  $ref: '#/components/schemas/OptimizePromptOptions'
                  description: 提示词优化选项
                output_format:
                  type: string
                  description: 输出图片格式，如 "png"、"jpeg"、"webp"
                background:
                  type: string
                  description: 设置生成图像的背景： "transparent" /"opaque"/ "auto" 默认为 "auto"
                output_compression:
                  type: integer
                  description: 输出压缩率
                response_format:
                  type: string
                  description: 响应格式，"url" 或 "b64_json"
                sequential_image_generation:
                  type: string
                  description: >-
                    控制是否关闭组图功能（组图：基于您输入的内容，生成的一组内容关联的图片）。"auto"/"disabled" 默认为
                    "disabled"
                sequential_image_generation_options:
                  $ref: '#/components/schemas/SequentialImageGenerationOptions'
                  description: 组图功能的配置。仅当 sequential_image_generation 为 auto 时生效。
                stream:
                  type: boolean
                  description: 是否使用流式响应（SSE）
                watermark:
                  type: boolean
                  description: 是否添加水印
              required:
                - model
                - prompt
            examples: {}
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  created:
                    type: integer
                    description: 图片生成时间戳（Unix 秒级时间戳）
                    format: int64
                  model:
                    type: string
                    description: 使用的模型名称
                  data:
                    type: array
                    items:
                      description: >-
                        单张图片数据。

                        包含图片的 URL 或 Base64 编码数据、修订后的提示词、图片尺寸等信息。

                        兼容 OpenAI DALL-E 格式（b64_json /
                        revised_prompt）及通用图像模型返回格式。
                      type: object
                      properties:
                        b64_json:
                          type: string
                          description: 图片的 Base64 编码数据（当 response_format 为 b64_json 时返回）
                        revised_prompt:
                          type: string
                          description: 模型自动修订后的提示词（DALL-E 3 特性）
                        output_format:
                          type: string
                          description: 输出图片格式，如 "png"、"jpeg"、"webp"
                        z_index:
                          type: integer
                          description: 图层叠放顺序
                        name:
                          type: string
                          description: 图层名称
                        bounding_box:
                          $ref: '#/components/schemas/BoundingBox'
                          description: 图层边界框
                        url:
                          type: string
                          description: 图片的可公开访问 URL 地址
                        size:
                          type: string
                          description: 图片尺寸，如 "1024x1024"
                        error:
                          $ref: '#/components/schemas/ImageError'
                          description: 当前图片生成过程中出现的错误信息（部分成功时填充）
                        description:
                          type: string
                          description: 图层描述
                    description: 生成的图片数据列表
                  usage:
                    description: Token 及图片用量统计
                    type: object
                    properties:
                      output_tokens:
                        type: integer
                        description: 输出 Token 消耗数量
                      total_tokens:
                        type: integer
                        description: 总 Token 消耗数量
                      generated_images:
                        type: integer
                        description: 本次请求生成的图片数量
                      input_images:
                        type: integer
                        description: 本次请求输入的图片数量
                description: ''
          headers: {}
      deprecated: false
      security: []
components:
  schemas:
    OptimizePromptOptions:
      type: object
      properties:
        mode:
          type: string
          description: '优化模式: standard/fast'
    SequentialImageGenerationOptions:
      type: object
      properties:
        max_images:
          type: integer
          description: 最大生成图片数量
    BoundingBox:
      type: object
      properties:
        absolute:
          type: array
          items:
            type: integer
          description: 绝对坐标
        normalized:
          type: array
          items:
            type: integer
          description: 归一化坐标
    ImageError:
      type: object
      properties:
        code:
          type: string
          description: 错误码
        message:
          type: string
          description: 错误描述信息
        type:
          type: string
          description: 错误类型分类
        param:
          type: string
          description: 导致错误的请求参数名

````