curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "seedream-5-0-260128",
"prompt": "Replace the clothing in image 1 with the outfit from image 2."
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "seedream-5-0-260128",
"prompt": "Replace the clothing in image 1 with the outfit from image 2."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'seedream-5-0-260128',
prompt: 'Replace the clothing in image 1 with the outfit from image 2.'
})
};
fetch('https://api.apiyi.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'seedream-5-0-260128',
'prompt' => 'Replace the clothing in image 1 with the outfit from image 2.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"seedream-5-0-260128\",\n \"prompt\": \"Replace the clothing in image 1 with the outfit from image 2.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"seedream-5-0-260128\",\n \"prompt\": \"Replace the clothing in image 1 with the outfit from image 2.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"seedream-5-0-260128\",\n \"prompt\": \"Replace the clothing in image 1 with the outfit from image 2.\"\n}"
response = http.request(request)
puts response.read_body{
"model": "seedream-5-0-260128",
"created": 1768518000,
"data": [
{
"url": "https://ark-content-generation-v2-ap-southeast-1.tos-ap-southeast-1.bytepluses.com/.../image.png",
"b64_json": "<string>",
"size": "2048x2048"
}
],
"usage": {
"generated_images": 1,
"output_tokens": 6240,
"total_tokens": 6240
}
}画像編集 API リファレンス
Seedream の画像編集、複数画像の融合、バッチ連続生成の API リファレンスとライブ プレイグラウンド — 画像配列と sequential_image_generation パラメータで切り替える、同じ generations エンドポイント
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "seedream-5-0-260128",
"prompt": "Replace the clothing in image 1 with the outfit from image 2."
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "seedream-5-0-260128",
"prompt": "Replace the clothing in image 1 with the outfit from image 2."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'seedream-5-0-260128',
prompt: 'Replace the clothing in image 1 with the outfit from image 2.'
})
};
fetch('https://api.apiyi.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'seedream-5-0-260128',
'prompt' => 'Replace the clothing in image 1 with the outfit from image 2.'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"seedream-5-0-260128\",\n \"prompt\": \"Replace the clothing in image 1 with the outfit from image 2.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"seedream-5-0-260128\",\n \"prompt\": \"Replace the clothing in image 1 with the outfit from image 2.\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"seedream-5-0-260128\",\n \"prompt\": \"Replace the clothing in image 1 with the outfit from image 2.\"\n}"
response = http.request(request)
puts response.read_body{
"model": "seedream-5-0-260128",
"created": 1768518000,
"data": [
{
"url": "https://ark-content-generation-v2-ap-southeast-1.tos-ap-southeast-1.bytepluses.com/.../image.png",
"b64_json": "<string>",
"size": "2048x2048"
}
],
"usage": {
"generated_images": 1,
"output_tokens": 6240,
"total_tokens": 6240
}
}/v1/images/edits エンドポイントはありません。編集、複数画像の融合、バッチシーケンスはすべて POST /v1/images/generations で行われます。このページのプレイグラウンドは テキストから画像生成 と同じエンドポイントを呼び出します — 唯一の違いは、リクエスト本文内の image と sequential_image_generation パラメータです。- 単一画像の編集 —
image: ["url"]+sequential_image_generation: "disabled" - 複数画像の融合 —
image: ["url1", "url2", ...]+disabled - バッチシーケンス —
sequential_image_generation: "auto"+sequential_image_generation_options.max_images: N - 画像からシーケンス — 2 つを組み合わせます:
image配列 +auto+max_images
response_format: "url" モードでは、Playground は問題なく動作します(レスポンスは一時的な BytePlus TOS リンクだけです)。response_format: "b64_json" に切り替えると、レスポンスに数 MB の base64 文字列が含まれ、ブラウザ版 Playground では 请求时发生错误: unable to complete request と表示されることがあります — リクエスト自体は実際には成功しています。ブラウザがそのような長い base64 文字列をレンダリングできないだけです。推奨ワークフロー:- 画像を表示したいだけですか? デフォルトの
urlモードのままにしてください — Playground はリンクを直接返します(24 時間以内にご自身のストレージへダウンロードしてください)。 - b64_json が必要ですか? 下のコードサンプルをコピーしてローカルで実行してください — コードが画像をデコードしてファイルに自動保存します。
- multipart/form-data アップロードは不要です — まず画像を OSS か公開画像ホストにアップロードし、その後
image配列に URL を渡します imageは URL 配列であり、繰り返しのimage[]フィールドではありません(OpenAI のmultipart/form-data形式とは異なります)maskフィールドはありません — Seedream はアルファチャンネルマスクのインペインティングをサポートしておらず、画像全体が prompt によって書き換えられます- 合計数には厳しい上限があります: 入力参照 + 出力 ≤ 15 枚の画像
image 配列内の URL の順序が、prompt で参照される「画像 1 / 画像 2 / 画像 3」になります。順序を明示してください:画像 1 の服を画像 2 の衣装に置き換え、画像 3 の照明は維持してください。英語の prompt が最も効果的です(モデルは主に英語で学習されています)が、表現が明確であれば中国語もサポートされています。
コード例
extra_bodyについて(重要 — 追加のネスト層だと誤解しないでください)image、sequential_image_generation、watermarkは、OpenAI SDK の images.generate() の標準パラメータではないため、Python SDK で送信するには extra_body 内に配置する必要があります。ただし、extra_bodyは SDK のパラメータコンテナにすぎず、そのフィールドは 最上位レベルにフラット化されて統合されます。リクエストボディでは、modelおよびpromptと同じレベルになります。実際に送信される JSON は、以下の cURL 例と同一です(imageは最上位レベルに配置されます)。リクエスト内に実際の "extra_body": {...} のネストはありません。OpenAI SDK を使用せず、JSON を直接(requests / fetch などで)構築する場合は、extra_bodyを記述しないでください。imageやその他のフィールドは、modelと同じレベルに配置してください。Python(OpenAI SDK · 単一画像編集)
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1"
)
resp = client.images.generate(
model="seedream-5-0-260128",
prompt="Generate a close-up image of a dog lying on lush grass.",
size="2K",
response_format="url",
# Fields in extra_body are flattened to the top level of the request body
# (same level as model) by the SDK — not an extra nesting layer
extra_body={
"image": ["https://your-oss.example.com/source-photo.png"],
"sequential_image_generation": "disabled",
"watermark": False,
}
)
print(resp.data[0].url)
Python(OpenAI SDK · 複数画像の融合)
resp = client.images.generate(
model="seedream-4-5-251128",
prompt="Replace the clothing in image 1 with the outfit from image 2, keeping the lighting style of image 3.",
size="4K",
response_format="url",
extra_body={
"image": [
"https://your-oss.example.com/person.png",
"https://your-oss.example.com/outfit.png",
"https://your-oss.example.com/lighting-ref.png",
],
"sequential_image_generation": "disabled",
"watermark": False,
}
)
print(resp.data[0].url)
Python(OpenAI SDK · バッチシーケンス)
resp = client.images.generate(
model="seedream-5-0-260128",
prompt=(
"Generate four cinematic sci-fi storyboard scenes:"
"Scene 1 — astronaut repairing a spacecraft;"
"Scene 2 — meteor strike in deep space;"
"Scene 3 — emergency dodge in zero gravity;"
"Scene 4 — astronaut returning to ship."
),
size="2K",
response_format="url",
extra_body={
"sequential_image_generation": "auto",
"sequential_image_generation_options": {"max_images": 4},
"watermark": False,
}
)
for item in resp.data:
print(item.url)
cURL(複数画像の融合)
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-260128",
"prompt": "Replace the clothing in image 1 with the outfit from image 2.",
"image": [
"https://your-oss.example.com/person.png",
"https://your-oss.example.com/outfit.png"
],
"sequential_image_generation": "disabled",
"size": "2K",
"response_format": "url",
"watermark": false
}'
Node.js(fetch · バッチシーケンス)
const resp = await fetch('https://api.apiyi.com/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key'
},
body: JSON.stringify({
model: 'seedream-5-0-260128',
prompt: 'A four-panel comic about a cat astronaut: launch, space walk, alien encounter, return home.',
size: '2K',
sequential_image_generation: 'auto',
sequential_image_generation_options: { max_images: 4 },
response_format: 'url',
watermark: false
})
});
const { data } = await resp.json();
data.forEach((item, i) => console.log(`#${i + 1}:`, item.url));
image配列のエントリが URL の場合、リクエストボディは数 KB にすぎず、BytePlus はシンガポールリージョンから画像を直接ダウンロードします(確認済み:取得元の IP は BytePlus に属しており、APIYI ゲートウェイは関与していません)。
エントリが data:image/...;base64,...文字列の場合、高解像度の参照画像を数枚指定するだけで、ボディのサイズは簡単に 20〜30 MB に達します。そのボディ全体をまず APIYI ゲートウェイにアップロードしてからシンガポールへ転送する必要があります。国境をまたぐアップロードが遅い場合、リクエストボディの読み取りに対するプロバイダーの 600 秒の受信制限を超過し、400 Error when parsing requestで失敗します。
リクエスト全体が失敗し、URL モードにはフォールバックしません。これは、ゲートウェイが base64 をダウンロード可能なリンクに変換してくれないためです。- ✅ 画像を自分のオブジェクトストレージまたは画像ホストに保存し、認証なしの通常の GET で取得できる公開 URL を渡してください。各画像は約 10 MB 未満にしてください
- ⚠️ base64 が避けられない場合は、先に圧縮してください:長辺を 2048 px 以内にし、品質 0.9 で再エンコードし、複数画像の場合は合計 6 MB 未満にしてください
- ❌ 20 MB を超える base64 ボディを送信したり、プライベートネットワークのアドレスやログインが必要なリンクを渡したりしないでください(取得に失敗すると BytePlus は
InvalidParameter: Error while downloadingを返します)
パラメータリファレンス
| パラメータ | 型 | 必須 | デフォルト値 | 説明 |
|---|---|---|---|---|
model | 文字列 | はい | — | seedream-5-0-260128 / seedream-4-5-251128 / seedream-4-0-250828 / seedream-5-0-pro-260628 (Proティア、$0.12/リクエスト) / seedream-5-0-flash-260915 (Fastティア、$0.018/リクエスト、参照画像は無料) |
prompt | 文字列 | はい | — | 編集 / 融合 / シーケンスの指示 |
image | 文字列の配列 | 編集時に必須 | — | URLまたはbase64データURIとしての参照画像(data:image/jpeg;base64,...、検証済み)、最大10枚(公式の4.5 / 5.0-pro / 5.0-flashドキュメントによる。弊社のテストでは5.0-flashで11枚目を指定すると400が返されます) |
sequential_image_generation | 文字列 | いいえ | disabled | 単一出力の場合はdisabled、バッチシーケンスの場合はauto。5.0-pro / 5.0-flashでは受け付けられません:任意の値(disabledを含む)で400が返されるため、これらのモデルではパラメータ自体を省略してください |
sequential_image_generation_options.max_images | 整数 | いいえ | — | autoでのみ有効。入力 + 出力 ≤ 15の制限があります。5.0-pro / 5.0-flashでは同様に受け付けられません |
size | 文字列 | いいえ | 2K | プリセットティアまたは正確なピクセル数 — ティアのサポート状況はバージョンによって異なります(概要を参照) |
response_format | 文字列 | いいえ | url | url / b64_json |
output_format | 文字列 | いいえ | jpeg | 5.0シリーズはpng / jpegをサポート、4.5 / 4.0はjpegのみをサポートします |
watermark | ブール値 | いいえ | 変動 | 商用利用の場合はfalseを設定してください(省略時、5.0-flashは「AI generated」の透かしを追加します) |
stream | ブール値 | いいえ | false | ストリーミング出力。長いpromptに推奨されます。5.0-pro / 5.0-flashでは受け付けられません — 400が返されます |
複数画像およびシーケンスモードにおけるカウント制約
| シナリオ | 入力 image 数 | max_images | 実際の出力 | 合計制約 |
|---|---|---|---|---|
| 単一画像編集 | 1 | — | 1 | 2 ≤ 15 ✅ |
| 複数画像合成 | 3 | — | 1 | 4 ≤ 15 ✅ |
| 複数画像合成 + シーケンス | 3 | 4 | 4 | 7 ≤ 15 ✅ |
| 複数画像合成 + シーケンス | 10 | 6 | 6 | 16 > 15 ❌ 却下 |
5.0 Flash レイヤー分離(透過レイヤー)
seedream-5-0-flash-260915は完成した画像を背景ベースと透過レイヤー上の個別要素に分離することができ、レイアウトの再調整、背景の差し替え、アセットの再利用に役立ちます。prompt内で透明な背景を指定してもアルファチャンネルは生成されないため、透過アセットが必要な場合はこの機能をご利用ください。
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash-260915",
"prompt": "Split the image into a background and separate layers for each element",
"image": ["https://your-oss.example.com/poster.jpg"],
"layer_decomposition": true,
"size": "1K",
"output_format": "png",
"response_format": "url",
"watermark": false
}'
- 参照画像1枚に対して、
data配列から12枚の画像が返されました。最初の1枚は要素が除去されて補完された背景ベース(ファイル名の末尾は_base.png、RGB)であり、残りの11枚はRGBA透過レイヤー(_layer_1.pngから)で、それぞれ自身のサイズに合わせて切り抜かれた1つの要素が含まれています - 1Kでは約78秒でした。同じリクエストを2Kで行った場合、15分経過しても何も返されませんでしたが、12枚分の画像として$0.216が課金されました。
1Kを使用し、クライアントのタイムアウトを300秒以上に設定してください - レイヤー分離は失敗することがあります。同じ画像で約60秒後に400が返されたケースがありました(
the image content could not be processed for layer decomposition)。失敗した場合は課金されませんので、再試行してください - ベースから除去された領域はモデルによって補完されるため、商用利用の前に確認してください
usage.generated_imagesは12でした)。レイヤー数は画像の内容に依存し、事前に設定することはできません。また、同じ画像であっても分離結果が毎回異なる場合があります(ある画像では12枚、次に14枚が出力され、それぞれ$0.216と$0.252が課金されました)。そのため、十数枚分以上の予算を見積もっておいてください。応答形式
{
"model": "seedream-5-0-260128",
"created": 1768518000,
"data": [
{
"url": "https://ark-content-generation-v2-ap-southeast-1.tos-ap-southeast-1.bytepluses.com/seedream-5-0/.../scene-1.png",
"size": "2048x2048"
},
{
"url": "https://...scene-2.png",
"size": "2048x2048"
}
],
"usage": {
"generated_images": 2,
"output_tokens": 12480,
"total_tokens": 12480
}
}
data 配列の長さは実際の出力数を反映しますsequential_image_generation: "disabled"→ 単一要素のdatasequential_image_generation: "auto"+max_images: N→ 通常は N 要素(prompt の生成結果が少ない場合は、さらに少なくなることがあります)- 課金は
usage.generated_images単位で、max_images単位ではありません
承認
API Key obtained from APIYI Console
ボディ
Model ID
seedream-5-0-260128, seedream-5-0-lite-260128, seedream-4-5-251128, seedream-4-0-250828, seedream-5-0-pro-260628, seedream-5-0-flash-260915 Editing / fusion / sequence instruction. For multi-image scenarios, refer to images explicitly as 'image 1 / image 2'
"Replace the clothing in image 1 with the outfit from image 2."
Reference image URL array. Up to 10 images (per official 4.5 / 5.0-pro / 5.0-flash docs; an 11th returns 400 on 5.0-flash in our tests). Note: input + output count ≤ 15
10[
"https://your-oss.example.com/person.png",
"https://your-oss.example.com/outfit.png"
]
Generation mode switch. disabled = single output (default); auto = batch sequence, paired with max_images. Not accepted by 5.0-pro / 5.0-flash — any value returns 400
disabled, auto Batch sequence options. Effective only when sequential_image_generation=auto
Show child attributes
Show child attributes
Output size. Preset tiers (vary by version):
1K(4.0 / 5.0-pro / 5.0-flash) /1.5K(5.0-flash only) /2K(all) /3K(5.0 only) /4K(4.5, 4.0)
Or exact pixel size WxH, total pixels ∈ [1280×720, 4096×4096], aspect ratio ∈ [1/16, 16]
"2K"
url, b64_json Output format. The 5.0 series supports png/jpeg; 4.5/4.0 only jpeg
png, jpeg 5.0-flash only: pass 1 reference image to get a background base plus several RGBA transparent layers. Billed per output image (12 in one test); use size 1K and a timeout of 300 seconds or more
Streaming output. Recommended for long prompts and multi-image sequence scenarios. Not accepted by 5.0-pro / 5.0-flash (returns 400)
レスポンス
Edited image generated successfully
このページは役に立ちましたか?