Skip to main content
POST
/
v1
/
images
/
generations
Generate an image from a text prompt
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",
  "size": "1920x1080",
  "output_format": "jpeg",
  "safety_tolerance": 2
}
'
{
  "created": 1776832476,
  "data": [
    {
      "url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
    }
  ]
}
The interactive Playground on the right supports live debugging. Fill in your API Key in the Authorization header (format: Bearer sk-xxx), choose model and size, enter the prompt, and send.
Use this page for “text generates image” — only a prompt is needed, no upload. For editing or multi-reference fusion of existing images, see the Image Editing endpoint.
⚠️ Key differences / unsupported parameters
  • Result URL is valid for only 10 minutesdata[0].url must be downloaded immediately, expired URLs return 404
  • width / height must be multiples of 16 — otherwise returns 400
  • prompt_upsampling is not supported on FLUX.2 [klein] — silently ignored
  • Total pixel cap is 4MP (~2048×2048) — exceeding returns 400
  • grounding search only on flux-2-max — other models will not trigger live search even with time-sensitive prompts

Code Examples

Python (OpenAI SDK Drop-in)

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 (Native requests · with width/height syntax)

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 (Native 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()));

Browser JavaScript (direct render)

{/* 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 Reference

ParameterTypeRequiredDefaultDescription
modelstringYesFLUX model ID, see table below
promptstringYesPrompt, up to 32K tokens. Supports natural language and structured JSON
sizestringNo1024x1024OpenAI-style size string, e.g., 1920x1080
widthintegerNo1024BFL-native, alternative to size, must be multiple of 16
heightintegerNo1024BFL-native, must be multiple of 16
seedintegerNorandomFix for reproducibility
safety_toleranceintegerNo20 (strictest) – 6 (most permissive)
output_formatstringNojpegjpeg / png
prompt_upsamplingbooleanNofalseAuto-expand prompt (not on [klein])
stepsintegerNo50Only for flux-2-flex, max 50
guidancenumberNo4.5Only for flux-2-flex, 1.5–10
nintegerNo1Only 1 supported

Supported Model IDs

Model IDSpeedBest For
flux-2-max< 15sFlagship + grounding search
flux-2-pro< 10sProduction at scale, best value
flux-2-flexSlowerTypography specialist
flux-2-klein-9bSub-secondBalanced
flux-2-klein-4bSub-secondFastest
flux-pro-1.1-ultra~10sLegacy 4MP (see Historical Versions)
flux-pro-1.1~5sLegacy 1.6MP
flux-pro~6sFirst-gen pro
flux-dev~5sDev/test
Detailed constraints, allowed values, and examples are visible in the right-side Playground field hints. All enum fields support dropdown selection.

Response Format

{
    "created": 1776832476,
    "data": [
        {
            "url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
        }
    ]
}
⚠️ data[0].url is valid for only 10 minutes
  • URL hosted on delivery-eu.bfl.ai / delivery-us.bfl.ai, signature expires after 10 min
  • CORS is disabled — browser fetch is blocked, but <img src> rendering works
  • Production services must server-side download to your own OSS / CDN
  • Unlike OpenAI’s gpt-image-2 (which returns b64_json), FLUX returns URL only — no base64.
FLUX does not return a usage field (priced per image, not per token). Actual billing follows the pricing table on this site. The response header x-request-id is for support tracing.

Authorizations

Authorization
string
header
required

API Key from the APIYI Console

Body

application/json
model
enum<string>
default:flux-2-pro
required

FLUX model ID. For FLUX.2 prefer flux-2-pro / flux-2-max; legacy versions in the Historical Versions page.

Available options:
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
string
required

Prompt, up to 32K tokens. Supports natural language, hex codes, and structured JSON.

Example:

"A cinematic shot of a futuristic city at sunset, 85mm lens"

size
string
default:1024x1024

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.

Example:

"1920x1080"

width
integer
default:1024

BFL-native syntax, alternative to size. Must be a multiple of 16, between 64 and 2048.

Required range: 64 <= x <= 2048
Example:

1920

height
integer
default:1024

BFL-native syntax. Must be a multiple of 16, between 64 and 2048.

Required range: 64 <= x <= 2048
Example:

1080

seed
integer

Fix for reproducibility — same seed + same other params yields the same result.

Example:

42

safety_tolerance
integer
default:2

Moderation level. 0 = strictest, 6 = most permissive, default 2.

Required range: 0 <= x <= 6
output_format
enum<string>
default:jpeg

Output format.

Available options:
jpeg,
png
prompt_upsampling
boolean
default:false

Auto-expand the prompt. Not supported on FLUX.2 [klein] (silently ignored).

steps
integer
default:50

Only flux-2-flex. Inference steps, max 50.

Required range: 1 <= x <= 50
guidance
number
default:4.5

Only flux-2-flex. Guidance scale. 1.5–10, higher = closer to prompt.

Required range: 1.5 <= x <= 10
n
enum<integer>
default:1

Number of images. Only 1 supported.

Available options:
1

Response

Image generated

created
integer

Unix timestamp

Example:

1776832476

data
object[]

Result array (single image per call)