Skip to main content

Black Forest Labs Image Generation

Black Forest Labs provides state-of-the-art text-to-image generation using their FLUX models.

Overview​

PropertyDetails
DescriptionBlack Forest Labs FLUX models for high-quality text-to-image generation
Provider Route on LiteLLMblack_forest_labs/
Provider DocBlack Forest Labs API ↗
Supported Operations/images/generations

Setup​

API Key​

import os

# Set your Black Forest Labs API key
os.environ["BFL_API_KEY"] = "your-api-key-here"

Get your API key from Black Forest Labs.

Supported Models​

Model NameDescriptionPrice
black_forest_labs/flux-pro-1.1Fast & reliable standard generation$0.04/image
black_forest_labs/flux-pro-1.1-ultraUltra high-resolution (up to 4MP)$0.06/image
black_forest_labs/flux-devDevelopment/open-source variant$0.025/image
black_forest_labs/flux-proOriginal pro model$0.05/image

Image Generation​

Usage - LiteLLM Python SDK​

Basic Image Generation
import os
import litellm

# Set your API key
os.environ["BFL_API_KEY"] = "your-api-key-here"

# Generate an image
response = litellm.image_generation(
model="black_forest_labs/flux-pro-1.1",
prompt="A beautiful sunset over the ocean with sailing boats",
)

# BFL returns URLs
print(response.data[0].url)

Usage - LiteLLM Proxy Server​

1. Configure your config.yaml​

Black Forest Labs Image Generation Configuration
model_list:
- model_name: flux-pro
litellm_params:
model: black_forest_labs/flux-pro-1.1
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_generation

- model_name: flux-ultra
litellm_params:
model: black_forest_labs/flux-pro-1.1-ultra
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_generation

- model_name: flux-dev
litellm_params:
model: black_forest_labs/flux-dev
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_generation

general_settings:
master_key: sk-1234

2. Start LiteLLM Proxy Server​

Start LiteLLM Proxy Server
litellm --config /path/to/config.yaml

# RUNNING on http://0.0.0.0:4000

3. Make image generation requests​

Black Forest Labs via Proxy - OpenAI SDK
from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
base_url="http://localhost:4000",
api_key="sk-1234"
)

# Generate image with FLUX Pro
response = client.images.generate(
model="flux-pro",
prompt="A beautiful garden with colorful flowers",
size="1024x1024",
)

print(response.data[0].url)

Supported Parameters​

OpenAI-Compatible Parameters​

ParameterTypeDescriptionMapping
promptstringText description of the image to generateDirect
modelstringThe FLUX model to useDirect
sizestringImage dimensions (e.g., 1024x1024)Maps to width and height
nintegerNumber of images (ultra model only, up to 4)Maps to num_images
qualitystringhd for natural lookMaps to raw=True for ultra
response_formatstringurl or b64_jsonDirect

Black Forest Labs Specific Parameters​

ParameterTypeDescriptionDefault
widthintegerImage width (256-1920, multiples of 16)1024
heightintegerImage height (256-1920, multiples of 16)1024
aspect_ratiostringAlternative to width/height (e.g., 16:9, 1:1)-
seedintegerSeed for reproducible resultsRandom
output_formatstringOutput format: png or jpegpng
safety_toleranceintegerSafety filter tolerance (0-6, higher = more permissive)2
prompt_upsamplingbooleanEnhance prompt for better resultsfalse

Ultra Model Specific Parameters​

ParameterTypeDescriptionDefault
rawbooleanRaw mode for more natural, less synthetic lookfalse
num_imagesintegerNumber of images to generate (1-4)1

How It Works​

Black Forest Labs uses a polling-based API:

  1. Submit Request: LiteLLM sends your prompt to BFL
  2. Get Task ID: BFL returns a task ID and polling URL
  3. Poll for Result: LiteLLM automatically polls until the image is ready
  4. Return Result: The generated image URL is returned

This polling is handled automatically by LiteLLM - you just call image_generation() and get the result.

Getting Started​

  1. Create an account at Black Forest Labs
  2. Get your API key from the dashboard
  3. Set your BFL_API_KEY environment variable
  4. Use litellm.image_generation() with any supported model

Additional Resources​