api.bfl.ai - Recommended for most use cases- Routes requests across all available clusters globally
- Automatic failover between clusters for enhanced uptime
- Intelligent load distribution prevents bottlenecks during high traffic
π FLUX.2 [klein] β Sub-second generation. Open weights, Apache 2.0, API from $0.014/image. Learn more β
Complete guide to FLUX API endpoints for AI image generation. Learn text-to-image creation, API polling, regional endpoints, and code examples.
Our API endpoints enable media creation with BFL models. It follows an asynchronous design, where you first make a request for a generation and then query for the result of your request.Documentation Index
Fetch the complete documentation index at: https://docs.bfl.ml/llms.txt
Use this file to discover all available pages before exploring further.
Primary Global Endpoint
api.bfl.ai - Recommended for most use casespolling_url returned in responses when using this endpointRegional Endpoints
api.eu.bfl.ai - European Multi-clusterapi.us.bfl.ai - US Multi-clusterapi.bfl.ai or regional endpoints api.eu.bfl.ai/api.us.bfl.ai for inference tasks./flux-2-max/flux-2-pro-preview β our latest FLUX.2 [pro]/flux-2-pro β a fixed snapshot of FLUX.2 [pro] for workflows that require reproducibility/flux-2-flex/flux-2-klein-4b/flux-2-klein-9b-preview β our latest FLUX.2 [klein] 9B with KV caching/flux-2-klein-9b β a fixed snapshot of FLUX.2 [klein] 9B for reproducibility/flux-kontext-max/flux-kontext-pro/flux-pro-1.1-ultra/flux-pro-1.1/flux-pro/flux-devflux-2-pro-preview, flux-2-klein-9b-preview) reflect our latest advances and are the best place to start. Choose non-preview endpoints when you need a pinned model for reproducibility. See Preview Endpoints for details.flux-2-pro-preview, our latest and most capable model:
# Install curl and jq, then run:
# Make sure to set your API key: export BFL_API_KEY="your_key_here"
request=$(curl -X 'POST' \
'https://api.bfl.ai/v1/flux-2-pro-preview' \
-H 'accept: application/json' \
-H "x-key: ${BFL_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"prompt": "A cat on its back legs running like a human is holding a big silver fish with its arms. The cat is running away from the shop owner and has a panicked look on his face. The scene is situated in a crowded market.",
"width": 1440,
"height": 2048
}')
echo $request
request_id=$(jq -r .id <<< $request)
polling_url=$(jq -r .polling_url <<< $request)
echo "Request ID: ${request_id}"
echo "Polling URL: ${polling_url}"
id and a polling_url that should be used to retrieve the result.
api.bfl.ai) or regional endpoints (api.eu.bfl.ai, api.us.bfl.ai), you must use the polling_url returned in the response for checking request status.polling_url:
# This assumes that the request_id and polling_url variables are set from the previous step
while true
do
sleep 0.5
result=$(curl -s -X 'GET' \
"${polling_url}" \
-H 'accept: application/json' \
-H "x-key: ${BFL_API_KEY}")
status=$(jq -r .status <<< $result)
echo "Status: $status"
if [ "$status" == "Ready" ]
then
echo "Result: $(jq -r .result.sample <<< $result)"
break
elif [ "$status" == "Error" ] || [ "$status" == "Failed" ]
then
echo "Generation failed: $result"
break
fi
done
result['sample'] is a signed URL for retrieval.
result.sample URLs are served from region-specific delivery endpoints under delivery.*.bfl.ai. Region identifiers are subject to change as we add or remove clusters, so if you need to whitelist these hosts, whitelist the wildcard delivery.*.bfl.ai rather than individual regions. These URLs are not meant to be served directly to users β we recommend downloading the image and re-serving it from your own infrastructure. We do not enable CORS on delivery URLs.429 and must wait until one of your previous tasks has finished.flux-kontext-max, requests to our API are limited to 6 active tasks.402), visit https://api.bfl.ai, sign in and click βAddβ to buy additional credits. See also Credits & Billing.Was this page helpful?