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

# Seedream 5.5 画像生成

> テキストまたは最大 10 枚の参照画像から画像を生成。透明背景、レイヤー数を調整できる分解、文字 OCR に対応する非同期 API。

```bash cURL theme={null}
curl --request POST \
  --url https://api.apimart.ai/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "seedream-5-5",
  "prompt": "An orange cat sticker with clean edges",
  "size": "2K",
  "background": "transparent",
  "output_format": "png"
}'
```

```python Python theme={null}
import requests

payload = {
  "model": "seedream-5-5",
  "prompt": "An orange cat sticker with clean edges",
  "size": "2K",
  "background": "transparent",
  "output_format": "png"
}
response = requests.post(
    "https://api.apimart.ai/v1/images/generations",
    headers={"Authorization": "Bearer <token>"},
    json=payload,
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

```javascript JavaScript theme={null}
const payload = {
  "model": "seedream-5-5",
  "prompt": "An orange cat sticker with clean edges",
  "size": "2K",
  "background": "transparent",
  "output_format": "png"
};
const response = await fetch("https://api.apimart.ai/v1/images/generations", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

```json 200 theme={null}
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_example_seedream55"
    }
  ]
}
```

`POST /v1/images/generations` に送信し、`data[0].task_id` を取得してから `GET /v1/tasks/{task_id}` で結果を確認します。

## モード

| モード | 指定方法 | 入力画像 | プロンプト |
| - | - | - | - |
| 画像生成 | デフォルト | 0～10 枚 | 必須 |
| レイヤー分解 | `layer_decomposition: true` | 必ず 1 枚 | 省略可能 |

## 認証

**Authorization** `string` *required*

`Authorization: Bearer <token>` を指定します。`<token>` は APIMart API Key です。

## リクエストパラメータ

**model** `string` *required*

`seedream-5-5` を指定します。

**prompt** `string`

テキストからの生成と画像からの生成では必須です。レイヤー分解では省略でき、被写体・文字・背景を自動で識別します。分解したい要素を指定することもできます。

**image\_urls** `string[]`

通常生成では参照画像は最大 10 枚、分解では必ず 1 枚です。公開画像 URL または画像の Base64 Data URI に対応します。ローカルファイルは[画像アップロード API](https://docs.apimart.ai/ja/api-reference/uploads/images.md)でアップロードし、返された `url` を渡します。

参照画像には、公開アクセス可能な `http(s)` URL または `data:image/<format>;base64,…` を使用します。Data URI の形式名は小文字で指定してください。

* JPEG、PNG、WebP、BMP、TIFF、GIF、HEIC、HEIF に対応。AVIF と JP2 は非対応です。
* 1 枚あたり **30 MiB（31,457,280 バイト）以下**、**総画素数 3600 万以下**。幅 × 高さで判定し、各辺 6000 ピクセルの上限ではありません。
* サイズ・総画素数の超過は同期的に HTTP 400。AVIF と JP2 はタスク作成後に上流で拒否される場合があり、失敗時に返金されます。送信前に形式を変換してください。

画像アップロード API には独自の対応形式制限があります。モデルが対応していてもアップロードできない形式は、公開 URL または Data URI を使用してください。

**size** `string`

通常生成のデフォルトは `2K`。解像度区分、縦横比、正確なピクセル数を指定できます。レイヤー分解はデフォルト `auto` で、`1K` / `1.5K` / `2K` / `auto` のみ対応します。

画像生成の `size: "auto"` は `2K` と同じです。縦横比形式で `resolution` を省略した場合も `2K` です。正確なピクセル指定では `resolution` を送らず、幅と高さを正の整数にしてください。

**resolution** `string`

画像生成では縦横比形式の `size` とともに `1K` / `1.5K` / `2K` を指定します。分解ではプラットフォームが提供する `size` の別名です。`size` が優先され、省略時のみ `resolution` を使用し、両方省略すると `auto` になります。分解で有効なのは `1K` / `1.5K` / `2K` / `auto` のみで、比率やピクセル指定は同期的に HTTP 400 となります。`3K` / `4K` は非対応です。

**background** `string`

通常生成では `auto`（デフォルト）/ `transparent` / `opaque`。テキストからも参照画像からも透明背景を生成できます。透明背景には PNG が必要で、`output_format: "jpeg"` は使えません。分解では `auto` を含め、このフィールドを送信しないでください。

**output\_format** `string` (default: png)

`png`（デフォルト）または `jpeg`。分解時はベース画像だけに適用され、分離したレイヤーは常に透明 PNG です。

**n** `integer`

`1` のみ。通常生成は 1 回につき 1 枚です。分解時の出力数は `layer_decomposition_options.max_images` で制御します。

**watermark** `boolean` (default: false)

透かしを付けるかを指定する省略可能なフラグ。

**optimize\_prompt\_options** `object`

`{"mode":"standard"}` のみ対応します。省略しても上流のデフォルト `standard` が有効となり、Seedream 5.5 では最適化を無効にできません。`disabled` / `none` / `off` は上流が HTTP 400 と `must be one of: standard` で拒否します。`fast` はプラットフォームの受付時に HTTP 400 となります。

**layer\_decomposition** `boolean`

`true` でベース画像と透明レイヤーに分解します。入力は必ず 1 枚で、`background` は指定できません。`output_format` はベース画像だけに適用されます。

**layer\_decomposition\_options** `object`

`layer_decomposition: true` の場合のみ指定可能です。それ以外では HTTP 400 になります。

**リクエストパラメータ**

**max\_images** `integer` (default: 30)

`2`～`100` の整数、デフォルト `30`。ベース画像を含む合計出力数の上限であり、指定枚数の生成を保証するものではありません。

**text\_recognition** `boolean` (default: false)

省略可能なブール値。`true` で文字レイヤーのリッチテキスト OCR を要求します。認識可能な通常の文字にだけ `text_recognition` が返る場合があります。

OCR を有効にしても、`prompt` を指定すると文字認識結果が返らない場合があります。OCR を優先する場合は分解プロンプトの省略を試してください。ただし返却は保証されないため、任意フィールドとして扱ってください。

## サイズの指定

| 形式 | 例 | ルール |
| - | - | - |
| 解像度区分 | `"size": "2K"` | `1K` / `1.5K` / `2K`。通常生成はデフォルト `2K`、縦横比はプロンプトに応じて決まります。 |
| 縦横比 + 解像度 | `"size": "16:9", "resolution": "1.5K"` | 通常生成のみ。下記の比率と `16x9` 形式に対応。 |
| ピクセル数 | `"size": "2048x1152"` | 通常生成のみ。総ピクセル数 921,600～4,624,220、幅/高さ 1/16～16。 |

対応比率：`1:1`、`4:3`、`3:4`、`16:9`、`9:16`、`3:2`、`2:3`、`21:9`、`2:1`、`1:2`。

制限は幅と高さの積および比率に適用されます。分解では解像度区分または `auto` のみ使用でき、比率やピクセル数は指定できません。

### レイヤー分解の出力サイズ

* 優先順位は `size` → `resolution` → `auto`。`resolution` はプラットフォームの別名で、上流に送信するのは `size` のみです。`size: "1K"` と `resolution: "2K"` の併用では `1K`、`resolution: "1.5K"` のみなら `1.5K` が適用されます。

* `1K` / `1.5K` / `2K` を指定すると、ベースと各レイヤーがそれぞれの縦横比を保持し、指定区分で出力されます。実測例では `1K` のベースは `840×1248`、各レイヤーも約 105 万ピクセルでした。固定の幅・高さではありません。

* `auto` は入力の元サイズを使用します。`1K` 未満は `1K` に拡大し、`2K` 超は `2K` に縮小します。

## リクエスト例

### 画像編集と参照画像の融合

```bash theme={null}
curl --request POST \
  --url https://api.apimart.ai/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "seedream-5-5",
  "prompt": "Combine the product in the first image with the setting in the second image",
  "image_urls": ["https://example.com/product.png", "https://example.com/setting.jpg"],
  "size": "16:9",
  "resolution": "1.5K",
  "output_format": "png"
}'
```

### レイヤー分解と文字 OCR

この例の出力はベース画像を含め最大 10 枚です。`prompt` は省略可能で、`background` は送信しません。画像 URL をアクセス可能なものに置き換えてください。

```bash theme={null}
curl --request POST \
  --url https://api.apimart.ai/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "seedream-5-5",
  "image_urls": ["https://example.com/poster.png"],
  "layer_decomposition": true,
  "layer_decomposition_options": {
    "max_images": 10,
    "text_recognition": true
  },
  "size": "1K"
}'
```

## タスクの照会

[タスク照会 API](https://docs.apimart.ai/ja/api-reference/tasks/status.md)を利用します。最初の 30 秒は 3 秒間隔、その後は 5～10 秒間隔で照会します。分解には数分かかる場合があり、サーバーの待機上限は 13 分です。`task_id` を保存して終了状態まで照会し、生成リクエストを重複送信しないでください。

```bash theme={null}
curl --request GET \
  --url 'https://api.apimart.ai/v1/tasks/task_example_seedream55' \
  --header 'Authorization: Bearer <token>'
```

`data.status` の `pending` / `processing` は処理中、`completed` は成功です。`failed` の場合は `data.error.message` を確認します。失敗時は自動返金されます。成功画像は `data.result.images[].url[]` から取得します。

> [!WARNING]
>
> 結果画像は **3 日間**保存されます。早めにダウンロードしてください。タスク記録も 3 日間のみ保持され、その後は `task_id` で照会できません。
>
> `data.result.images[].expires_at` は現在、タスク完了時刻 + 24 時間の Unix 秒を返します。実際の削除より早い保守的な目安であり、実際の保存期間や削除までのカウントダウンの計算には使用しないでください。

## レイヤー結果と OCR

以下は構造の説明用であり、実測結果ではありません。サイズ・座標・文字は例です。メタデータは省略される場合があります。

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_example_seedream55",
    "status": "completed",
    "progress": 100,
    "completed": 1794302642,
    "result": {
      "images": [
        {
          "url": ["https://example.com/base.png", "https://example.com/title.png"],
          "sizes": ["840x1248", "1512x702"],
          "output_formats": ["png", "png"],
          "backgrounds": ["opaque", "transparent"],
          "expires_at": 1794389042,
          "layer_decomposition": true,
          "layers": [
            {
              "z_index": 0,
              "size": "840x1248",
              "output_format": "png",
              "background": "opaque"
            },
            {
              "z_index": 1,
              "size": "1512x702",
              "output_format": "png",
              "background": "transparent",
              "name": "Sale title",
              "description": "Printed sale title",
              "bounding_box": {
                "absolute": [84, 156, 756, 468],
                "normalized": [100, 125, 900, 375]
              },
              "text_recognition": {
                "text": "SUMMER SALE",
                "lines": [
                  {
                    "bounding_box": {
                      "absolute": [126, 156, 714, 468],
                      "normalized": [150, 125, 850, 375]
                    },
                    "runs": [
                      {
                        "text": "SUMMER SALE",
                        "style": {
                          "similar_font_family": "Arial",
                          "foreground_color": "#222222",
                          "bold": true,
                          "italic": false,
                          "underline": false,
                          "strikethrough": false,
                          "shadow": false,
                          "translucent": false
                        }
                      }
                    ]
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  }
}
```

各 `data.result.images[]` 内の `url`、`sizes`、`output_formats`、`backgrounds`、`layers` は同じ添字で対応します。メタデータ配列の長さが `url` と一致しない場合、そのフィールドが省略されることがあります。

| フィールド | 説明 |
| - | - |
| `url[]` | 画像の URL。分解時は 0 番目がベース画像で、その後に各レイヤーが続きます。早めにダウンロードして保存してください。 |
| `sizes[]` / `output_formats[]` | 各画像の実際のサイズと形式。 |
| `backgrounds[]` | 実際の背景は `opaque` / `transparent`。`background: "auto"` では返された値を参照します。 |
| `expires_at` | 現在はタスク完了時刻 + 24 時間（86400 秒）の Unix タイムスタンプです。保守的な目安であり、実際の画像削除時刻を表しません。削除までのカウントダウンには使用しないでください。 |
| `layer_decomposition` | レイヤー分解の結果かどうか。 |
| `layers[i].z_index` | 重ねる順序。ベースは 0 で、昇順に合成します。 |
| `layers[i].background` | ベースは `opaque`、各レイヤーは `transparent`。 |
| `layers[i].name` / `description` | 省略可能なレイヤー名と説明。 |
| `layers[i].bounding_box` | `absolute` はベース画像上のピクセル座標 `[left, top, right, bottom]`。`normalized` は同じ枠を 0～1000 に正規化した値です。ベースにはありません。 |
| `layers[i].text_recognition` | OCR が有効で通常の文字を認識した場合のみ返ることがあります。装飾文字、手書き、文字以外のレイヤーには返りません。 |

絶対座標では `x=left`、`y=top`、`w=right-left`、`h=bottom-top`。`W × H` のキャンバスでは正規化座標を次のように変換します。

```text theme={null}
x = left / 1000 * W
y = top / 1000 * H
w = (right - left) / 1000 * W
h = (bottom - top) / 1000 * H
```

各レイヤーは指定区分で個別に出力されるため、ファイル寸法と `bounding_box` の寸法は異なる場合があります。合成時は枠の `w × h` に拡縮して `(x, y)` に配置してください。レイヤーのピクセルをそのままベース座標として扱わないでください。

### 文字認識フィールド

`text_recognition` は上流モデルの OCR 構造に従います。プラットフォームは `text`、`lines`、`runs`、`style` などを変更せず返します。

| フィールド | 説明 |
| - | - |
| `text` | レイヤー全体のテキスト。改行は `\n`。 |
| `lines[].bounding_box` | ベース画像上の行の境界枠。座標系は上記と同じです。 |
| `lines[].runs[]` | 同じ行のスタイル別テキスト断片。各要素に `text` と `style` があります。 |
| `runs[].style.similar_font_family` | 最も近いフォント名。不明な場合は `unknown`。 |
| `runs[].style.foreground_color` | `#RRGGBB` 形式の文字色。 |
| `runs[].style.bold` / `italic` / `underline` / `strikethrough` / `shadow` / `translucent` | モデルが推定したブール値のスタイル情報。誤差がある場合があります。 |

OCR とフォント情報は表示・コピー・編集の補助に使えますが、元画像との完全な一致は保証されません。OCR がなくてもレイヤー画像は使用できます。

## 課金

出力画像と入力参照画像は別々に課金されます。**最初の画像を含め参照画像はすべて有料**で、レイヤー分解に使う 1 枚も対象です。

* 出力ごとの実際の総画素数が **2,610,000 以下**なら低い区分、超える場合は高い区分です。`1K` / `1.5K` は低い区分、`2K` は高い区分。正確なサイズ指定は幅 × 高さで判定します。
* 画像生成では選択した出力区分の料金と、参照枚数 × 入力画像単価を仮引き落としします。`size` の省略または `auto` は `2K` で確保します。
* 分解では `max_images` × 出力の仮引き落とし単価に、**入力画像 1 枚分の料金**を加えて確保します。既定の `max_images` はベースを含む 30 枚で、実際の出力は少ない場合があります。
* 分解では有効な `size`（省略時は `resolution`）を使用し、`1K` / `1.5K` は低い区分、`2K` / `auto` は高い区分で確保します。両方省略時も `auto` の高い区分です。
* 完了後は実際の出力枚数、各画像の総画素数区分、入力枚数で精算し、差額を返金または追加請求します。ベースと各レイヤーをそれぞれ 1 枚と数え、全画像にリクエスト区分を一律適用しません。失敗時は全額返金されます。

単価は[モデル料金](https://apimart.ai/pricing)をご覧ください。

## よくあるパラメータエラー

プラットフォームと上流の検証エラーを含みます。送信失敗は `error.message`、非同期タスク失敗は `data.error.message` を確認してください。

| エラー抜粋 | 対処方法 |
| - | - |
| `does not support optimize_prompt_options.mode=fast` | 受付時に同期的に HTTP 400。`standard` のみ使用でき、省略しても最適化は有効です。 |
| `must be one of: standard` | 上流の HTTP 400：`disabled` / `none` / `off` は非対応で、最適化を無効にできません。 |
| `only supports background auto, transparent or opaque` | `auto`、`transparent`、`opaque` を使用します。 |
| `cannot combine background=transparent with output_format=jpeg` | 透明背景では `output_format: "png"` を指定します。 |
| `does not accept background when layer_decomposition=true` | 分解では `auto` を含め `background` を削除します。 |
| `layer_decomposition_options requires layer_decomposition=true` | 分解モードでのみ送信します。 |
| `layer_decomposition_options.max_images must be within [2, 100]` | ベース画像を含め `max_images` は 2～100 の整数にします。 |
| `invalid layer_decomposition_options` | `max_images` は文字列や小数ではなく整数、`text_recognition` はブール値にします。 |
| `with layer_decomposition=true requires exactly 1 input image` | 分解の入力画像は必ず 1 枚にします。 |
| `only supports size 1K, 1.5K, 2K or auto` | 分解では `size` を優先し、なければ `resolution`。`1K` / `1.5K` / `2K` / `auto` のみで、比率やピクセル指定は同期的に HTTP 400 となります。 |
| `` `n` must be 1 `` | `n` は `1` にします。組画像生成は非対応です。 |
| `does not support stream` / `does not support tools` | `sequential_image_generation`、`stream`、`tools` を削除します。 |
| `supports up to 10 reference images` | 参照画像は最大 10 枚です。 |
| `reference image too large for seedream-5-5` | 参照画像は 1 枚 30 MiB 以下、総画素数 3600 万以下。圧縮・縮小してから再試行してください。 |
| `does not support size` / `requires total pixels` / `requires aspect ratio` | 総画素数、縦横比、サイズ表記を確認してください。3K / 4K は非対応です。 |
| `` `prompt` parameter is required `` | 画像生成にはプロンプトが必須です。省略できるのはレイヤー分解のみです。 |

## タスク失敗の理由

`data.status` が `failed` の場合、`data.error.message` と `data.error.reason` を確認します。料金は自動返金されます。`reason` がない、または未対応の値の場合は `message` を表示してください。

| `data.error.reason` | 対応 |
| - | - |
| `content_policy_violation` | 入力または出力がコンテンツ審査を通過しませんでした。プロンプトや画像を変更してください。 |
| `invalid_parameter` / `unsupported_option` | 非対応のパラメータまたは組み合わせです。リクエストを修正してください。 |
| `invalid_media` | 入力画像が破損しているか形式が非対応です。確認・変換してください。 |
| `media_unreachable` | 画像 URL にアクセスできません。公開アクセスを確認するか再アップロードしてください。 |
| `generation_timeout` | 生成がタイムアウトしました。時間をおいて再試行してください。 |
| `service_unavailable` | サービスが一時的に混雑しています。時間をおいて再試行してください。 |
| `delivery_failed` / `internal_error` / `unknown_error` | 配信またはプラットフォーム内部エラー。返された説明に従い、時間をおいて再試行してください。 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.