Skip to main content
POST
Generate an image from a text prompt
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
All image APIs are synchronous — there is no task ID to poll, and if your client disconnects the result is lost while the request is still billed. Set a generous timeout for this model; see Image API Essentials & Best Practices.

Code Examples

Python (OpenAI SDK Drop-in)

Python (Native requests · with width/height syntax)

cURL

Node.js (Native fetch)

Browser JavaScript (direct render)

Parameter Reference

Supported Model IDs

Detailed constraints, allowed values, and examples are visible in the right-side Playground field hints. All enum fields support dropdown selection.

Response Format

⚠️ 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)