Skip to main content

Black Forest Labs Image Editing

Black Forest Labs provides powerful image editing capabilities using their FLUX models to modify existing images based on text descriptions.

Overview​

PropertyDetails
DescriptionBlack Forest Labs Image Editing uses FLUX Kontext and other models to modify, inpaint, and expand images based on text prompts.
Provider Route on LiteLLMblack_forest_labs/
Provider DocBlack Forest Labs API ↗
Supported Operations/images/edits

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 NameDescriptionUse Case
black_forest_labs/flux-kontext-proFLUX Kontext Pro - General image editing with promptsGeneral editing, style transfer
black_forest_labs/flux-kontext-maxFLUX Kontext Max - Premium quality editingHigh-quality edits
black_forest_labs/flux-pro-1.0-fillFLUX Pro Fill - Inpainting with maskRemove/replace objects
black_forest_labs/flux-pro-1.0-expandFLUX Pro Expand - OutpaintingExpand image borders

Image Editing​

Usage - LiteLLM Python SDK​

Basic Image Editing
import os
import litellm

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

# Edit an image with a prompt
response = litellm.image_edit(
model="black_forest_labs/flux-kontext-pro",
image=open("path/to/your/image.png", "rb"),
prompt="Add a green leaf to the scene",
)

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

Usage - LiteLLM Proxy Server​

1. Configure your config.yaml​

Black Forest Labs Image Editing Configuration
model_list:
- model_name: bfl-kontext-pro
litellm_params:
model: black_forest_labs/flux-kontext-pro
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_edit

- model_name: bfl-kontext-max
litellm_params:
model: black_forest_labs/flux-kontext-max
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_edit

- model_name: bfl-fill
litellm_params:
model: black_forest_labs/flux-pro-1.0-fill
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_edit

- model_name: bfl-expand
litellm_params:
model: black_forest_labs/flux-pro-1.0-expand
api_key: os.environ/BFL_API_KEY
model_info:
mode: image_edit

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 editing 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"
)

# Edit image with FLUX Kontext Pro
response = client.images.edit(
model="bfl-kontext-pro",
image=open("path/to/your/image.png", "rb"),
prompt="Add magical sparkles and fairy dust",
)

print(response.data[0].url)

Supported Parameters​

OpenAI-Compatible Parameters​

ParameterTypeDescriptionDefault
imagefileThe image file to editRequired
promptstringText description of the desired changesRequired
modelstringThe FLUX model to useRequired
maskfileMask image for inpainting (flux-pro-1.0-fill)Optional
nintegerNumber of images (BFL returns 1 per request)1
sizestringMaps to aspect_ratioOptional
response_formatstringurl or b64_jsonurl

Black Forest Labs Specific Parameters​

ParameterTypeDescriptionDefaultModels
seedintegerSeed for reproducible resultsRandomAll
output_formatstringOutput format: png or jpegpngAll
safety_toleranceintegerSafety filter tolerance (0-6)2All
aspect_ratiostringOutput aspect ratio (e.g., 16:9, 1:1)OriginalKontext models
stepsintegerNumber of inference stepsModel defaultFill
guidancefloatGuidance scaleModel defaultFill
grow_maskintegerPixels to grow mask0Fill
topintegerPixels to expand at top0Expand
bottomintegerPixels to expand at bottom0Expand
leftintegerPixels to expand at left0Expand
rightintegerPixels to expand at right0Expand

How It Works​

Black Forest Labs uses a polling-based API:

  1. Submit Request: LiteLLM sends your image and 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_edit() 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_edit() with any supported model

Additional Resources​