curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "flux-2-pro",
"prompt": "Naturally blend these two images",
"input_image": "https://static.apiyi.com/apiyi-logo.png"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "Naturally blend these two images",
"input_image": "https://static.apiyi.com/apiyi-logo.png"
}
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: 'flux-2-pro',
prompt: 'Naturally blend these two images',
input_image: 'https://static.apiyi.com/apiyi-logo.png'
})
};
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' => 'flux-2-pro',
'prompt' => 'Naturally blend these two images',
'input_image' => 'https://static.apiyi.com/apiyi-logo.png'
]),
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\": \"flux-2-pro\",\n \"prompt\": \"Naturally blend these two images\",\n \"input_image\": \"https://static.apiyi.com/apiyi-logo.png\"\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\": \"flux-2-pro\",\n \"prompt\": \"Naturally blend these two images\",\n \"input_image\": \"https://static.apiyi.com/apiyi-logo.png\"\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\": \"flux-2-pro\",\n \"prompt\": \"Naturally blend these two images\",\n \"input_image\": \"https://static.apiyi.com/apiyi-logo.png\"\n}"
response = http.request(request)
puts response.read_body{
"created": 1776832476,
"data": [
{
"url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
}
]
}画像編集 API リファレンス
FLUX 画像編集 API リファレンスとライブデバッガー — 参照画像を最大 8 枚アップロードし、単一画像の編集や複数参照の融合のための指示を入力できます。FLUX.2 と FLUX.1 Kontext に対応します。
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "flux-2-pro",
"prompt": "Naturally blend these two images",
"input_image": "https://static.apiyi.com/apiyi-logo.png"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "Naturally blend these two images",
"input_image": "https://static.apiyi.com/apiyi-logo.png"
}
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: 'flux-2-pro',
prompt: 'Naturally blend these two images',
input_image: 'https://static.apiyi.com/apiyi-logo.png'
})
};
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' => 'flux-2-pro',
'prompt' => 'Naturally blend these two images',
'input_image' => 'https://static.apiyi.com/apiyi-logo.png'
]),
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\": \"flux-2-pro\",\n \"prompt\": \"Naturally blend these two images\",\n \"input_image\": \"https://static.apiyi.com/apiyi-logo.png\"\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\": \"flux-2-pro\",\n \"prompt\": \"Naturally blend these two images\",\n \"input_image\": \"https://static.apiyi.com/apiyi-logo.png\"\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\": \"flux-2-pro\",\n \"prompt\": \"Naturally blend these two images\",\n \"input_image\": \"https://static.apiyi.com/apiyi-logo.png\"\n}"
response = http.request(request)
puts response.read_body{
"created": 1776832476,
"data": [
{
"url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
}
]
}Bearer sk-xxx)。参照画像1の 公開URL を input_image に貼り付けます。複数参照の場合は、追加画像の URL を input_image_2 … input_image_8 に入力します。次に prompt / model を入力して送信してください。Playground は URL のみ受け付けます。base64 の data URL 入力の場合は、下のコードサンプルをコピーしてローカルで実行してください。- オプション A(このページの Playground、推奨): JSON +
input_imageから/v1/images/generationsへ(テキストから画像生成と共通で、input_imageを送信すると編集モードになります)。すべての FLUX モデル(Kontext を含み、検証済み)で動作し、複数参照の融合(input_image_2~input_image_8)をサポートします。 - オプション B: OpenAI 互換の multipart エンドポイント
/v1/images/edits(下の「オプション B」セクションを参照)— 単一画像の編集に対応し、OpenAI SDK のclient.images.edit()と直接互換です。
- エンドポイントパス:
/v1/images/generations(テキストから画像生成と共通です。OpenAI 互換の単一画像用/v1/images/editsエンドポイントもあります — オプション B を参照してください) - Content-Type:
application/json(オプション B の/editsエンドポイントでは代わりにmultipart/form-dataを使用します) - 各参照画像フィールドは文字列です:
input_image/input_image_2…input_image_8は公開URL(推奨)またはdata:image/...;base64,xxxdata URL を受け付けます - 参照画像の上限はモデルごとに異なります: FLUX.2 [pro/max/flex] は最大 8、FLUX.2 [klein] は最大 4、FLUX.1 Kontext はネイティブで 1 をサポートします
- 各画像は 20MB または 20MP 以下、形式は
png/jpg/webpです - 入力解像度: 最小 64×64、最大 4MP。寸法は 16 の倍数である必要があります
- 結果URLの有効期限は 10 分のみです —
data[0].urlはすぐにダウンロードする必要があります aspect_ratioが省略された場合、出力寸法は最初の入力画像と一致します
input_image / input_image_2 / input_image_3 … の番号付けは、プロンプト内の 「image 1 / image 2 / image 3」 で使われるインデックスとまったく同じです。image 1 の人物を image 2 のシーンに配置し、image 3 のカラーパレットを適用します。各値は、公開アクセス可能な URL(20MB 以下を推奨)または
data:image/png;base64,xxx data URL である必要があります。コード例
cURL (2画像フュージョン · URL)
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "flux-2-pro",
"prompt": "Naturally blend these two images",
"input_image": "https://static.apiyi.com/apiyi-logo.png",
"input_image_2": "https://images.unsplash.com/photo-1762138012600-2ab523f8b35a",
"seed": 42,
"output_format": "jpeg"
}'
cURL (3画像フュージョン · URL)
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "flux-2-pro",
"prompt": "The person from image 1 is petting the cat from image 2, the bird from image 3 is next to them",
"input_image": "https://example.com/person.jpg",
"input_image_2": "https://example.com/cat.jpg",
"input_image_3": "https://example.com/bird.jpg",
"seed": 42,
"output_format": "jpeg"
}'
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": "flux-kontext-pro",
"prompt": "Convert this architectural photo into a pencil sketch style, preserve all structural details",
"input_image": "https://your-oss.example.com/architecture.jpg"
}'
cURL (ローカルファイル · base64 データ URL)
# Encode local image as base64 data URL (macOS / Linux)
B64=$(base64 -w0 < person.png 2>/dev/null || base64 < person.png | tr -d '\n')
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d "$(jq -nc --arg img "data:image/png;base64,$B64" '{
model: "flux-2-pro",
prompt: "Stylize image 1 as an oil painting",
input_image: $img
}')"
Python (requests · 2画像フュージョン)
import requests
resp = requests.post(
"https://api.apiyi.com/v1/images/generations",
headers={
"Authorization": "Bearer sk-your-api-key",
"Content-Type": "application/json",
},
json={
"model": "flux-2-pro",
"prompt": "Naturally blend these two images",
"input_image": "https://static.apiyi.com/apiyi-logo.png",
"input_image_2": "https://images.unsplash.com/photo-1762138012600-2ab523f8b35a",
"seed": 42,
"output_format": "jpeg",
},
timeout=120,
)
image_url = resp.json()["data"][0]["url"]
# data[0].url is valid for only 10 minutes — download immediately
with open("fused.jpg", "wb") as f:
f.write(requests.get(image_url, timeout=30).content)
Python (requests · ローカルファイルを base64 として)
import base64, requests, mimetypes
def to_data_url(path: str) -> str:
mime = mimetypes.guess_type(path)[0] or "image/png"
with open(path, "rb") as f:
b64 = base64.b64encode(f.read()).decode()
return f"data:{mime};base64,{b64}"
resp = requests.post(
"https://api.apiyi.com/v1/images/generations",
headers={
"Authorization": "Bearer sk-your-api-key",
"Content-Type": "application/json",
},
json={
"model": "flux-2-pro",
"prompt": "Place the person from image 1 into the scene from image 2",
"input_image": to_data_url("person.png"),
"input_image_2": "https://your-oss.example.com/scene.jpg",
},
timeout=120,
)
print(resp.json()["data"][0]["url"])
Python (OpenAI SDK · extra_body 経由で input_image を渡す)
from openai import OpenAI
import requests
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1"
)
# OpenAI SDK images.generate() targets /v1/images/generations with JSON;
# BFL-native fields are added straight into the body via extra_body.
resp = client.images.generate(
model="flux-2-pro",
prompt="Naturally blend these two images",
extra_body={
"input_image": "https://static.apiyi.com/apiyi-logo.png",
"input_image_2": "https://images.unsplash.com/photo-1762138012600-2ab523f8b35a",
"seed": 42,
"output_format": "jpeg",
},
)
image_url = resp.data[0].url
with open("fused.jpg", "wb") as f:
f.write(requests.get(image_url, timeout=30).content)
Node.js (fetch · 複数参照フュージョン)
const resp = await fetch('https://api.apiyi.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-your-api-key',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'flux-2-pro',
prompt: 'Naturally blend these two images',
input_image: 'https://static.apiyi.com/apiyi-logo.png',
input_image_2: 'https://images.unsplash.com/photo-1762138012600-2ab523f8b35a',
seed: 42,
output_format: 'jpeg',
}),
});
const { data } = await resp.json();
const img = await fetch(data[0].url);
const fs = await import('node:fs');
fs.writeFileSync('fused.jpg', Buffer.from(await img.arrayBuffer()));
オプション B: OpenAI互換の編集エンドポイント(multipart)
上の JSON オプションに加えて、FLUX の画像編集は標準の OpenAI Images API edit endpoint もサポートしており、client.images.edit() と直接互換性があります(flux-kontext-max で 2026-07-04 に検証済み、生成成功):
- エンドポイント:
POST https://api.apiyi.com/v1/images/edits - Content-Type:
multipart/form-data(SDK と curl-Fによって自動設定されます — 手動で設定しないでください。設定すると boundary が失われ、解析に失敗します)
input_image ~ input_image_8)を使用してください。オプション B は現在、Kontext series で検証されています。リクエストパラメータ(フォームフィールド)
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
model | 文字列 | ✓ | 例: flux-kontext-max / flux-kontext-pro |
prompt | 文字列 | ✓ | 編集指示 |
image | ファイル | ✓ | 元画像のバイナリ(png/jpg/webp、≤ 20MB)。フィールド名は image である必要があります — 省略すると image is required が返されます |
aspect_ratio | 文字列 | ✗ | 例: 1:1 / 16:9。トップレベルのフォームフィールドとして渡します。OpenAI SDK のユーザーは extra_body で渡します |
safety_tolerance | 整数 | ✗ | 0(最も厳格)– 6(最も寛容) |
cURL の例
curl -X POST "https://api.apiyi.com/v1/images/edits" \
-H "Authorization: Bearer sk-your-api-key" \
-F "model=flux-kontext-max" \
-F "prompt=Change the outfit to a fashion look" \
-F "aspect_ratio=16:9" \
-F "[email protected]"
Python(OpenAI SDK)の例
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1",
)
result = client.images.edit(
model="flux-kontext-max",
image=open("input.jpg", "rb"),
prompt="Change the outfit to a fashion look",
extra_body={"aspect_ratio": "16:9"}, # FLUX-specific params go through extra_body
)
print(result.data[0].url)
Node.js(fetch + FormData)の例
const form = new FormData();
form.append('model', 'flux-kontext-max');
form.append('prompt', 'Change the outfit to a fashion look');
form.append('aspect_ratio', '16:9');
form.append('image', imageBlob, 'input.jpg'); // browser Blob or Node's fs.openAsBlob()
const resp = await fetch('https://api.apiyi.com/v1/images/edits', {
method: 'POST',
headers: { 'Authorization': 'Bearer sk-your-api-key' },
// Note: do NOT set Content-Type manually — let the runtime generate the multipart boundary
body: form,
});
const data = await resp.json();
console.log(data.data[0].url);
data[0].url、10分間有効な BFL 署名付き URL — 本番環境ではサーバー側で自分のストレージにダウンロードしてください)と同じです。
どのオプションを使うべきですか?
オプション A(JSON input_image) | オプション B(multipart /edits) | |
|---|---|---|
| 最適な用途 | 直接 HTTP / フロントエンドアプリ / 複数参照の融合 | 既存の OpenAI SDK コード、client.images.edit() の移行 |
| 複数画像 | はい(flux-2 は最大 8 枚) | 1枚のみ |
| 画像入力 | 公開 URL または base64 data URL | バイナリファイル |
パラメータリファレンス
| 項目 | 型 | 必須 | デフォルト | 説明 |
|---|---|---|---|---|
model | 文字列 | はい | — | FLUX のモデル ID。複数参照の融合では flux-2-pro / flux-2-max を優先し、単一画像の編集では flux-kontext-max / flux-kontext-pro も使用します |
prompt | 文字列 | はい | — | 編集 / 融合の指示。最大 32K tokens まで。「image 1 / image 2 / image 3」を使って image / input_image_2 / input_image_3 の順序を参照します |
input_image | 文字列 | はい | — | 参照画像 1。公開 URL(推奨)または data:image/...;base64,xxx data URL |
input_image_2 … input_image_8 | 文字列 | いいえ | — | 参照画像 2–8 — URL または data URL。FLUX.2 [pro/max/flex] は最大 8 枚、[klein] は 4 枚、Kontext は追加画像をサポートしません |
aspect_ratio | 文字列 | いいえ | 最初の入力に一致 | 例: 1:1 / 16:9 / 9:16 / 4:3 / 3:2 |
seed | 整数 | いいえ | ランダム | 再現性のために固定 |
safety_tolerance | 整数 | いいえ | 2 | 0(最も厳格)– 6(最も寛容) |
output_format | 文字列 | いいえ | jpeg | jpeg / png |
prompt_upsampling | ブール値 | いいえ | false | プロンプトを自動アップサンプルします |
steps | 整数 | いいえ | 50 | flux-2-flex のみ、最大 50 |
guidance | 数値 | いいえ | 4.5 | flux-2-flex のみ、1.5–10 |
マルチリファレンス戦略
キャラクターの一貫性(最大8枚)
キャラクターの一貫性(最大8枚)
Eight consistent characters from the reference images,
in a fashion editorial set on a Tokyo rooftop at golden hour
スタイル変換
スタイル変換
Using the style of image 2, render the subject from image 1
オブジェクト合成
オブジェクト合成
The person from image 1 is petting the cat from image 2,
the bird from image 3 is next to them
服装 / 商品の差し替え
服装 / 商品の差し替え
Replace the top of the person in image 1 with the one from image 2,
keep the pose and background unchanged
data[0].urlをダウンロードし、次の呼び出しで新しい指示とともにinput_imageとして再投入し、段階的に洗練します。各ラウンドは画像1枚分として課金されます。レスポンス形式
{
"created": 1776832476,
"data": [
{
"url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
}
]
}
data[0].url は10分間のみ有効ですdelivery-eu.bfl.ai/delivery-us.bfl.aiにホストされた URL、署名は10分後に期限切れになります- CORS は無効です — ブラウザの
fetchはブロックされます - 本番環境では、サーバーサイドで自前の OSS / CDN にダウンロードする必要があります
- FLUX の編集エンドポイントは
b64_jsonを返しません — URL のみです
FAQ
エラー image is required (shell_api_error) の原因は何ですか?
エラー image is required (shell_api_error) の原因は何ですか?
/v1/images/edits エンドポイント(オプション B)に届きましたが、ゲートウェイはリクエスト本文内に画像を見つけられませんでした。よくある原因は次のとおりです:- multipartフォームに
imageの file フィールドがない、またはフィールド名が間違っている場合です(例:image[],file) Content-Type: multipart/form-dataが boundary なしで手動設定されている(SDK / fetch / curl を使う場合は、このヘッダーを自分で設定しないでください)- クライアント側の画像変換に失敗したにもかかわらず、そのままリクエストが送信された場合です(
imageフィールドに実際に 0 バイトより多く入っていることを確認してください) - JSON で画像を送るつもりだったのに
/editsに当たってしまった場合です — JSON +input_imageは/v1/images/generations(オプション A)に送られます
承認
API Key from the APIYI Console
ボディ
FLUX model ID. For multi-reference fusion prefer flux-2-pro / flux-2-max; for single-image edits also flux-kontext-max / flux-kontext-pro.
flux-2-pro, flux-2-max, flux-2-flex, flux-2-klein-9b, flux-2-klein-4b, flux-kontext-max, flux-kontext-pro Edit / fusion instruction. In multi-reference scenarios, refer to images by index: 'image 1' / 'image 2' / 'image 3' map to input_image / input_image_2 / input_image_3.
"Naturally blend these two images"
Public URL for reference image 1 (required). Use plain URLs in the Playground; for local code you can also pass a data:image/png;base64,xxx data URL.
"https://static.apiyi.com/apiyi-logo.png"
Public URL for reference image 2 (optional)
Public URL for reference image 3 (optional)
Public URL for reference image 4 (optional)
Public URL for reference image 5 (optional)
Public URL for reference image 6 (optional)
Public URL for reference image 7 (optional)
Public URL for reference image 8 (optional, only FLUX.2 [pro/max/flex] supports up to 8)
Aspect ratio, e.g. 1:1 / 16:9 / 9:16 / 4:3 / 3:4. Defaults to first input image.
Fix for reproducibility.
Moderation level. 0 = strictest, 6 = most permissive. Default 2.
0 <= x <= 6Output format. Default jpeg.
jpeg, png Auto-upsample the prompt. Default false.
Only flux-2-flex. Inference steps. Default 50.
1 <= x <= 50Only flux-2-flex. Guidance scale. Default 4.5.
1.5 <= x <= 10このページは役に立ちましたか?