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": "A cinematic shot of a futuristic city at sunset, 85mm lens"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "A cinematic shot of a futuristic city at sunset, 85mm lens"
}
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: 'A cinematic shot of a futuristic city at sunset, 85mm lens'
})
};
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' => 'A cinematic shot of a futuristic city at sunset, 85mm lens'
]),
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\": \"A cinematic shot of a futuristic city at sunset, 85mm lens\"\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\": \"A cinematic shot of a futuristic city at sunset, 85mm lens\"\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\": \"A cinematic shot of a futuristic city at sunset, 85mm lens\"\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 リファレンスとライブデバッガー — OpenAI互換のドロップインで FLUX.2 [klein/pro/max/flex] ファミリー全体を利用可能、4MP 出力と正確な hex カラー制御
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": "A cinematic shot of a futuristic city at sunset, 85mm lens"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "A cinematic shot of a futuristic city at sunset, 85mm lens"
}
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: 'A cinematic shot of a futuristic city at sunset, 85mm lens'
})
};
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' => 'A cinematic shot of a futuristic city at sunset, 85mm lens'
]),
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\": \"A cinematic shot of a futuristic city at sunset, 85mm lens\"\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\": \"A cinematic shot of a futuristic city at sunset, 85mm lens\"\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\": \"A cinematic shot of a futuristic city at sunset, 85mm lens\"\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)、モデルとサイズを選択して、prompt を入力し、送信してください。- 結果 URL の有効期限は 10 分のみ —
data[0].urlはすぐにダウンロードしてください。期限切れの URL は 404 を返します width/heightは 16 の倍数である必要があります — そうでない場合は 400 を返しますprompt_upsamplingは FLUX.2 [klein] ではサポートされていません — 何もせずに無視されます- 総ピクセル上限は 4MP (~2048×2048) — 超えると 400 を返します
grounding searchはflux-2-maxでのみ利用可能です — 時間に敏感な prompt でも、他のモデルではライブ検索は起動しません
コード例
Python (OpenAI SDK ドロップイン)
from openai import OpenAI
import requests
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1"
)
resp = client.images.generate(
model="flux-2-pro",
prompt="A cinematic shot of a futuristic city at sunset, 85mm lens, hyper-realistic",
size="1920x1080"
)
# data[0].url is valid for only 10 minutes — download immediately
image_url = resp.data[0].url
with open("out.jpg", "wb") as f:
f.write(requests.get(image_url, timeout=30).content)
Python (ネイティブ requests · width/height 構文付き)
import requests
API_KEY = "sk-your-api-key"
response = requests.post(
"https://api.apiyi.com/v1/images/generations",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"model": "flux-2-max",
"prompt": "Score of yesterday's Champions League final, infographic style",
"width": 1920,
"height": 1080,
"safety_tolerance": 2,
"output_format": "jpeg",
"seed": 42
},
timeout=120
).json()
image_url = response["data"][0]["url"]
with open("out.jpg", "wb") as f:
f.write(requests.get(image_url, timeout=30).content)
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-2-pro",
"prompt": "Luxury eyeshadow palette with 6 pans: top row #B76E79, #E8D5B7, #8B4789; bottom row #CD7F32, #F8F6F0, #800020",
"size": "1024x1024",
"output_format": "png"
}'
Node.js (ネイティブ fetch)
import fs from 'node:fs';
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: 'flux-2-klein-9b',
prompt: 'A serene mountain landscape at golden hour, soft diffused light',
width: 1024,
height: 1024
})
});
const { data } = await resp.json();
// Download immediately — URL expires in 10 minutes
const img = await fetch(data[0].url);
fs.writeFileSync('out.jpg', Buffer.from(await img.arrayBuffer()));
ブラウザ JavaScript (直接レンダリング)
{/* Demo only — production should proxy via backend to avoid leaking the key. The delivery URL has CORS disabled, so server-side download to your own CDN is recommended. */}
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: 'flux-2-pro',
prompt: 'Watercolor aurora borealis over Nordic mountains',
size: '1536x1024'
})
});
const { data } = await resp.json();
{/* delivery URL has CORS disabled, but <img src> works for direct rendering. Server-side download is still recommended for production. */}
document.getElementById('img').src = data[0].url;
パラメータリファレンス
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | FLUX モデル ID、下の表を参照してください |
prompt | string | Yes | — | Prompt、最大 32K tokens。自然言語と構造化 JSON をサポートします |
size | string | No | 1024x1024 | OpenAI 形式のサイズ文字列、例: 1920x1080 |
width | integer | No | 1024 | BFL ネイティブ、size の代替。16 の倍数である必要があります |
height | integer | No | 1024 | BFL ネイティブ、16 の倍数である必要があります |
seed | integer | No | random | 再現性のための固定値 |
safety_tolerance | integer | No | 2 | 0(最も厳格)– 6(最も寛容) |
output_format | string | No | jpeg | jpeg / png |
prompt_upsampling | boolean | No | false | Prompt を自動拡張します([klein] では無効) |
steps | integer | No | 50 | flux-2-flex のみ、最大 50 |
guidance | number | No | 4.5 | flux-2-flex のみ、1.5–10 |
n | integer | No | 1 | 1 のみサポートされています |
サポートされているモデル ID
| Model ID | Speed | Best For |
|---|---|---|
flux-2-max | < 15s | フラッグシップ + grounding search |
flux-2-pro | < 10s | 大規模な本番運用、最も高い価値 |
flux-2-flex | Slower | タイポグラフィ専門 |
flux-2-klein-9b | Sub-second | バランス型 |
flux-2-klein-4b | Sub-second | 最速 |
flux-pro-1.1-ultra | ~10s | レガシー 4MP(Historical Versions を参照) |
flux-pro-1.1 | ~5s | レガシー 1.6MP |
flux-pro | ~6s | 初代 Pro |
flux-dev | ~5s | 開発/テスト |
レスポンス形式
{
"created": 1776832476,
"data": [
{
"url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
}
]
}
data[0].url は10分間のみ有効です- URL は
delivery-eu.bfl.ai/delivery-us.bfl.aiでホストされ、署名は10分後に期限切れになります - CORS は無効です — ブラウザの
fetchはブロックされますが、<img src>のレンダリングは動作します - 本番サービスでは、必ずサーバー側で自分の OSS / CDN にダウンロードしてください
- OpenAI の
gpt-image-2(b64_jsonを返す)とは異なり、FLUX は URL のみを返します — base64 はありません。
usage フィールドを返しません(課金は token ではなく画像ごとです)。実際の課金はこのサイトの料金表に従います。レスポンスヘッダー x-request-id はサポート用のトレースに使用されます。承認
API Key from the APIYI Console
ボディ
FLUX model ID. For FLUX.2 prefer flux-2-pro / flux-2-max; legacy versions in the Historical Versions page.
flux-2-max, flux-2-pro, flux-2-flex, flux-2-klein-9b, flux-2-klein-4b, flux-pro-1.1-ultra, flux-pro-1.1, flux-pro, flux-dev Prompt, up to 32K tokens. Supports natural language, hex codes, and structured JSON.
"A cinematic shot of a futuristic city at sunset, 85mm lens"
OpenAI-style size string. Pick either size or width+height.
Common: 1024x1024 / 1536x1024 / 1024x1536 / 1920x1080 / 1440x2048 / 2048x2048.
Custom must satisfy: multiples of 16, 64×64–4MP.
"1920x1080"
BFL-native syntax, alternative to size. Must be a multiple of 16, between 64 and 2048.
64 <= x <= 20481920
BFL-native syntax. Must be a multiple of 16, between 64 and 2048.
64 <= x <= 20481080
Fix for reproducibility — same seed + same other params yields the same result.
42
Moderation level. 0 = strictest, 6 = most permissive, default 2.
0 <= x <= 6Output format.
jpeg, png Auto-expand the prompt. Not supported on FLUX.2 [klein] (silently ignored).
Only flux-2-flex. Inference steps, max 50.
1 <= x <= 50Only flux-2-flex. Guidance scale. 1.5–10, higher = closer to prompt.
1.5 <= x <= 10Number of images. Only 1 supported.
1 このページは役に立ちましたか?