FLUX.1 is a state-of-the-art text-to-image generation AI model series developed by Black Forest Labs. This GitHub repository provides the official inference code for the FLUX.1 models, allowing users to run image generation and editing functionalities.
FLUX.1 offers multiple versions to meet different needs:
FLUX.1 [schnell]
FLUX.1 [dev]
FLUX.1 [pro]
cd $HOME && git clone https://github.com/black-forest-labs/flux
cd $HOME/flux
python3.10 -m venv .venv
source .venv/bin/activate
pip install -e ".[all]"
If TensorRT support is required, use NVIDIA's PyTorch image:
cd $HOME && git clone https://github.com/black-forest-labs/flux
enroot import 'docker://$oauthtoken@nvcr.io#nvidia/pytorch:25.01-py3'
enroot create -n pti2501 nvidia+pytorch+25.01-py3.sqsh
enroot start --rw -m ${PWD}/flux:/workspace/flux -r pti2501
cd flux
pip install -e ".[tensorrt]" --extra-index-url https://pypi.nvidia.com
from flux.api import ImageRequest
# Create an API request
request = ImageRequest("A beautiful beach", name="flux.1.1-pro")
# Or use an API key: request = ImageRequest("A beautiful beach", name="flux.1.1-pro", api_key="your_key_here")
# Get the result URL
request.url
# -> https:<...>/sample.jpg
# Get the image byte data
request.bytes
# -> b"..." bytes for the generated image
# Save to local
request.save("outputs/api.jpg")
# Get the PIL image object
request.image
# -> a PIL image
# Get the URL of the generated image
$ python -m flux.api --prompt="A beautiful beach" url
https:<...>/sample.jpg
# Generate and save the result
$ python -m flux.api --prompt="A beautiful beach" save outputs/api
# Display the image directly
$ python -m flux.api --prompt="A beautiful beach" image show
Black Forest Labs provides a complete API service:
export BFL_API_KEY=<your_key_here>
Or provide it directly in the code:
api_key="your_key_here"
FLUX.1 represents the highest level of current text-to-image generation technology. Through its advanced architecture design and multi-version strategy, it provides a powerful and flexible image generation solution for various users, from researchers to commercial users. Whether pursuing rapid prototyping for speed or requiring the highest quality for professional applications, FLUX.1 can provide the corresponding solution.