> ## 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 image generation

> Image generation compatible with the official Seedream protocol, supporting text-to-image, image-to-image, sequential images, and layer decomposition

This endpoint is consistent with the official Seedream protocol. It extends the OpenAI Images protocol with Seedream-specific parameters, supporting reference image input, sequential image generation, and layer decomposition.

## Features

* Compatible with the base parameters of the OpenAI Images protocol (`prompt`, `size`, `output_format`, and more)
* Supports image-to-image generation by passing a reference image via `image` (URL or Base64)
* Supports sequential image generation via `sequential_image_generation`, producing a set of related images from your input, with a configurable maximum count
* Supports layer decomposition via `layer_decomposition`, returning decomposed layers with bounding box information
* Supports prompt optimization via `optimize_prompt_options` (`standard` / `fast` modes)
* Supports both resolution tiers such as `1K` and `2K` and explicit sizes such as `1024x1024`
* Supports watermark control via `watermark`

## Authentication

Include the `Authorization` header in the format `Bearer YOUR_API_KEY`.

## Supported image models

Models in the seedream series.

## Quick example

<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": "An orange cat wearing an astronaut helmet floating in space with Earth in the background",
      "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: 'An orange cat wearing an astronaut helmet floating in space with Earth in the background',
      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": "An orange cat wearing an astronaut helmet floating in space with Earth in the background",
      "size": "2K",
      "watermark": false,
      "response_format": "url"
    }'
  ```
</CodeGroup>

A successful generation returns the image data:

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

## Next steps

* See [OpenAI image generation](/docs/en/api-reference/images/openai/generation) for the base protocol parameters
* See [OpenAI image edit](/docs/en/api-reference/images/openai/edit) to edit existing images
* See the [model list](/docs/en/api-reference/models/list-models) for available image models


## OpenAPI

````yaml en/api-reference/images/seedream/generation/openapi.json POST /v1/images/generations
openapi: 3.0.1
info:
  title: Default Module
  description: ''
  version: 1.0.0
servers: []
security: []
tags: []
paths:
  /v1/images/generations:
    post:
      tags: []
      summary: Seedream image generation
      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: Model name
                prompt:
                  type: string
                  description: Text prompt
                image:
                  type: object
                  properties: {}
                  description: >-
                    Reference image, URL or Base64 string (Seedream extension
                    parameter, used for image-to-image)
                layer_decomposition:
                  type: boolean
                  description: >-
                    Whether to decompose layers: true to decompose, false not to
                    (default)
                size:
                  type: string
                  description: Image size, e.g. "1024x1024", "1K", "2K"
                optimize_prompt_options:
                  $ref: '#/components/schemas/OptimizePromptOptions'
                  description: Prompt optimization options
                output_format:
                  type: string
                  description: Output image format, e.g. "png", "jpeg", "webp"
                background:
                  type: string
                  description: >-
                    Background of the generated image: "transparent" / "opaque"
                    / "auto"; defaults to "auto"
                output_compression:
                  type: integer
                  description: Output compression level
                response_format:
                  type: string
                  description: Response format, "url" or "b64_json"
                sequential_image_generation:
                  type: string
                  description: >-
                    Controls whether to disable sequential image generation
                    (sequential images: a set of related images generated from
                    your input). "auto"/"disabled"; defaults to "disabled"
                sequential_image_generation_options:
                  $ref: '#/components/schemas/SequentialImageGenerationOptions'
                  description: >-
                    Sequential image generation configuration. Only effective
                    when sequential_image_generation is auto.
                stream:
                  type: boolean
                  description: Whether to use streaming (SSE) responses
                watermark:
                  type: boolean
                  description: Whether to add a watermark
              required:
                - model
                - prompt
            examples: {}
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  created:
                    type: integer
                    description: Image generation timestamp (Unix seconds)
                    format: int64
                  model:
                    type: string
                    description: Model used
                  data:
                    type: array
                    items:
                      description: >-
                        Single image data.

                        Contains the image URL or Base64 data, the revised
                        prompt, the image size, and more.

                        Compatible with the OpenAI DALL-E format (b64_json /
                        revised_prompt) and common image model response formats.
                      type: object
                      properties:
                        b64_json:
                          type: string
                          description: >-
                            Base64-encoded image data (returned when
                            response_format is b64_json)
                        revised_prompt:
                          type: string
                          description: Prompt revised by the model (DALL-E 3 feature)
                        output_format:
                          type: string
                          description: Output image format, e.g. "png", "jpeg", "webp"
                        z_index:
                          type: integer
                          description: Layer stacking order
                        name:
                          type: string
                          description: Layer name
                        bounding_box:
                          $ref: '#/components/schemas/BoundingBox'
                          description: Layer bounding box
                        url:
                          type: string
                          description: Publicly accessible image URL
                        size:
                          type: string
                          description: Image size, e.g. "1024x1024"
                        error:
                          $ref: '#/components/schemas/ImageError'
                          description: >-
                            Error that occurred while generating this image
                            (populated on partial success)
                        description:
                          type: string
                          description: Layer description
                    description: Generated image data list
                  usage:
                    description: Token and image usage statistics
                    type: object
                    properties:
                      output_tokens:
                        type: integer
                        description: Output token consumption
                      total_tokens:
                        type: integer
                        description: Total token consumption
                      generated_images:
                        type: integer
                        description: Number of images generated in this request
                      input_images:
                        type: integer
                        description: Number of input images in this request
                description: ''
          headers: {}
      deprecated: false
      security: []
components:
  schemas:
    OptimizePromptOptions:
      type: object
      properties:
        mode:
          type: string
          description: 'Optimization mode: standard/fast'
    SequentialImageGenerationOptions:
      type: object
      properties:
        max_images:
          type: integer
          description: Maximum number of images to generate
    BoundingBox:
      type: object
      properties:
        absolute:
          type: array
          items:
            type: integer
          description: Absolute coordinates
        normalized:
          type: array
          items:
            type: integer
          description: Normalized coordinates
    ImageError:
      type: object
      properties:
        code:
          type: string
          description: Error code
        message:
          type: string
          description: Error description
        type:
          type: string
          description: Error type classification
        param:
          type: string
          description: Request parameter that caused the error

````