Loading...
Loading...
BFL FLUX API integration guide covering endpoints, async polling patterns, rate limiting, error handling, webhooks, and regional endpoints with Python and TypeScript code examples.
npx skill4agent add black-forest-labs/skills bfl-apiecho $BFL_API_KEY| Region | Endpoint | Use Case |
|---|---|---|
| Global | | Default, automatic failover |
| EU | | GDPR compliance |
| US | | US data residency |
Credit pricing: 1 credit = $0.01 USD. FLUX.2 uses megapixel-based pricing (cost scales with resolution).
| Model | Path | 1st MP | +MP | 1MP T2I | 1MP I2I | Best For |
|---|---|---|---|---|---|---|
| FLUX.2 [klein] 4B | | 1.4c | 0.1c | $0.014 | $0.015 | Real-time, high volume |
| FLUX.2 [klein] 9B | | 1.5c | 0.2c | $0.015 | $0.017 | Balanced quality/speed |
| FLUX.2 [pro] | | 3c | 1.5c | $0.03 | $0.045 | Production, fast turnaround |
| FLUX.2 [max] | | 7c | 3c | $0.07 | $0.10 | Maximum quality |
| FLUX.2 [flex] | | 5c | 5c | $0.05 | $0.10 | Typography, adjustable controls |
| FLUX.2 [dev] | - | - | - | Free | Free | Local development (non-commercial) |
Pricing formula:in cents(firstMP + (outputMP-1) * mpPrice) + (inputMP * mpPrice)
| Model | Path | Price/Image | Best For |
|---|---|---|---|
| FLUX.1 Kontext [pro] | | $0.04 | Image editing with context |
| FLUX.1 Kontext [max] | | $0.08 | Max quality editing |
| FLUX1.1 [pro] | | $0.04 | Standard T2I, fast & reliable |
| FLUX1.1 [pro] Ultra | | $0.06 | Ultra high-resolution |
| FLUX1.1 [pro] Raw | | $0.06 | Candid photography feel |
| FLUX.1 Fill [pro] | | $0.05 | Inpainting |
Tip: All FLUX.2 models support image editing via theparameter - no separate editing endpoint needed. Use bfl.ai/pricing calculator for exact costs at different resolutions.input_image
curl -X POST "https://api.bfl.ai/v1/flux-2-pro" \
-H "x-key: $BFL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Change the background to a sunset",
"input_image": "https://example.com/photo.jpg"
}'curl -X POST "https://api.bfl.ai/v1/flux-2-pro" \
-H "x-key: $BFL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "The person from image 1 in the environment from image 2",
"input_image": "https://example.com/person.jpg",
"input_image_2": "https://example.com/background.jpg"
}'| Model | Max References |
|---|---|
| FLUX.2 [klein] | 4 images |
| FLUX.2 [pro/max/flex] | 8 images |
input_imageinput_image_2input_image_3input_image_8For detailed multi-reference patterns (character consistency, style transfer, pose guidance), seeflux-best-practices/rules/multi-reference-editing.md
| Tier | Concurrent Requests |
|---|---|
| Standard (most endpoints) | 24 |
| Approach | Use When |
|---|---|
| Polling | Scripts, CLI tools, local development, single requests, simple integrations |
| Webhooks | Production apps, high volume, server-to-server, when you need immediate notification |
polling_urlwebhook_urlBFL_API_KEYecho $BFL_API_KEY.envecho 'BFL_API_KEY=bfl_your_key_here' >> .env
echo '.env' >> .gitignore # Don't commit secretsx-key: YOUR_API_KEY1. POST request to model endpoint
└─> Response: { "polling_url": "..." }
2. GET polling_url (repeat until complete)
└─> Response: { "status": "Pending" | "Ready" | "Error", ... }
3. When Ready, download result URL
└─> URL expires in 10 minutes - download immediatelyflux-best-practices/rules/multi-reference-editing.mdNote: cURL examples are preferred by default as they work universally without requiring Python or Node.js. Use language-specific clients when building production applications.
curl -s -X POST "https://api.bfl.ai/v1/flux-2-pro" \
-H "x-key: $BFL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "A serene mountain landscape at sunset", "width": 1024, "height": 1024}'{ "id": "abc123", "polling_url": "https://api.bfl.ai/v1/get_result?id=abc123" }curl -s "POLLING_URL" -H "x-key: $BFL_API_KEY"{ "status": "Ready", "result": { "sample": "https://...", "seed": 1234 } }curl -s -o output.png "IMAGE_URL"Tip: Result URLs expire in 10 minutes. Download immediately after status becomes.Ready
curl -s -X POST "https://api.bfl.ai/v1/flux-2-pro" \
-H "x-key: $BFL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "The cat from image 1 sitting in the cozy room from image 2",
"input_image": "https://example.com/cat.jpg",
"input_image_2": "https://example.com/room.jpg",
"width": 1024,
"height": 1024
}'