All skills
Skillintermediate

Black Forest Labs Image Editing

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Claude Code Knowledge Pack7/10/2026

Overview

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


# 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


# 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)

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

async def edit_image():
    response = await litellm.aimage_edit(
        model="black_forest_labs/flux-kontext-pro",
        image=open("path/to/your/image.png", "rb"),
        prompt="Make this image look like a watercolor painting",
    )
    print(response.data[0].url)

# Run the async function
asyncio.run(edit_image())

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

# Use flux-pro-1.0-fill for inpainting
response = litellm.image_edit(
    model="black_forest_labs/flux-pro-1.0-fill",
    image=open("path/to/your/image.png", "rb"),
    mask=open("path/to/mask.png", "rb"),  # White areas will be edited
    prompt="Replace with a beautiful garden",
    steps=50,  # BFL-specific parameter
    guidance=30,  # BFL-specific parameter
)

print(response.data[0].url)

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

# Use flux-pro-1.0-expand to extend image borders
response = litellm.image_edit(
    model="black_forest_labs/flux-pro-1.0-expand",
    image=open("path/to/your/image.png", "rb"),
    prompt="Continue the scene with a mountain landscape",
    top=256,     # Expand 256 pixels at top
    bottom=256,  # Expand 256 pixels at bottom
    left=128,    # Expand 128 pixels at left
    right=128,   # Expand 128 pixels at right
)

print(response.data[0].url)

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

# Edit image with BFL-specific parameters
response = litellm.image_edit(
    model="black_forest_labs/flux-kontext-pro",
    image=open("path/to/your/image.png", "rb"),
    prompt="Transform into cyberpunk style with neon lights",
    seed=42,                    # For reproducible results
    output_format="png",        # png or jpeg
    safety_tolerance=2,         # 0-6, higher = more permissive
    aspect_ratio="16:9",        # Output aspect ratio
)

print(response.data[0].url)

Usage - LiteLLM Proxy Server

1. Configure your config.yaml

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

litellm --config /path/to/config.yaml

# RUNNING on http://0.0.0.0:4000

3. Make image editing requests

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)
curl --location 'http://localhost:4000/v1/images/edits' \\
--header 'Authorization: Bearer sk-1234' \\
--form 'model="bfl-kontext-pro"' \\
--form 'prompt="Add a sunset in the background"' \\
--form 'image=@"path/to/your/image.png"'

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