Our API endpoints enable media creation with BFL generative models. It follows an asynchronous design, where you first make a request for a generation and then query for the result of your request.

Available Endpoints

We currently support the following endpoints for image generation:

  1. /flux-kontext-pro
  2. /flux-kontext-max
  3. /flux-pro-1.1-ultra
  4. /flux-pro-1.1
  5. /flux-pro
  6. /flux-dev

Create Your First Image

Submit Generation Request

To submit an image generation task with FLUX 1.1 [pro], create a request:

# 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.us1.bfl.ai/v1/flux-kontext-pro' \
  -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.",
  "aspect_ratio": "1:1",
}')

echo $request
request_id=$(jq -r .id <<< $request)
echo "Request ID: ${request_id}"

A successful response will be a json object containing the request’s id, that will be used to retrieve the actual result.

Poll for Results

To retrieve the result, poll the get_result endpoint:

# This assumes that the request_id variable is set from the previous step

while true
do
  sleep 0.5
  result=$(curl -s -X 'GET' \
    "https://api.us1.bfl.ai/v1/get_result?id=${request_id}" \
    -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

A successful response will be a JSON object containing the result, where result['sample'] is a signed URL for retrieval.

Our signed URLs are only valid for 10 minutes. Please retrieve your result within this timeframe.

See our reference documentation for a full list of options and our inference repo.

Limits

Rate Limits: Sending requests to our API is limited to 24 active tasks. If you exceed your limit, you’ll receive a status code 429 and must wait until one of your previous tasks has finished.

Rate Limits: Additionally, due to capacity issues, for flux-kontext-max, the requests to our API is limited to 6 active tasks.

Credits: If you run out of credits (status code 402), visit https://api.us1.bfl.ai, sign in and click “Add” to buy additional credits. See also managing your account.

If you require higher volumes, please contact us at flux@blackforestlabs.ai