Skip to content

Getting Started

Note

  • The API is still in beta and subject to change.

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.

We currently support the following endpoints for image generation:

1 /flux-pro-1.1-ultra

2 /flux-pro-1.1

3 /flux-pro

4 /flux-dev

Creating request with FLUX 1.1 [pro]

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

Install curl and run

request=$(curl -X 'POST' \
  'https://api.bfl.ml/v1/flux-pro-1.1' \
  -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": 1024,
  "height": 768
}')
echo $request
request_id=$(jq -r .id <<< $request)

Install requests (e.g. pip install requests) and run

import os
import requests

request = requests.post(
    'https://api.bfl.ml/v1/flux-pro-1.1',
    headers={
        'accept': 'application/json',
        'x-key': os.environ.get("BFL_API_KEY"),
        'Content-Type': 'application/json',
    },
    json={
        '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': 1024,
        'height': 768,
    },
).json()
print(request)
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 result

To retrieve the result, you can poll the get_result endpoint:

This assumes that the request id is stored in a request_id variable as it was done in the previous step.

while true
do
  sleep 0.5
  result=$(curl -s -X 'GET' \
    "https://api.bfl.ml/v1/get_result?id=${request_id}" \
    -H 'accept: application/json' \
    -H "x-key: ${BFL_API_KEY}")
  if [ "$( jq -r .status <<< $result )" == "Ready" ]
  then
    echo "Result: $(jq -r .result.sample <<< $result)"
    break
  else
    echo "Status: $(jq -r .status <<< $result)"
  fi
done

This assumes that the request id is stored in a request_id variable and that the os and requests packages were imported as it was done in the previous step.

import time

while True:
    time.sleep(0.5)
    result = requests.get(
        'https://api.bfl.ml/v1/get_result',
        headers={
            'accept': 'application/json',
            'x-key': os.environ.get("BFL_API_KEY"),
        },
        params={
            'id': request_id,
        },
    ).json()
    if result["status"] == "Ready":
        print(f"Result: {result['result']['sample']}")
        break
    else:
        print(f"Status: {result['status']}")

A successful response will be a json object containing the result and the result['sample'] is signed url for retreival.

Note

Our signed urls are only valid for 10 minutes. So please retreive your result in 10 minutes.

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

Limits

Please note that sending requests to our API is limited to 24 active tasks. If you exceed your limit, it will return a status code 429 and you will have to wait until one of your previous tasks has finished. If you require higher volumes, please contact us at flux@blackforestlabs.ai

If you run out of credits (status code 402) you can go to https://api.bfl.ml, sign in and click "Add" to buy additional credits. See also here.