Black Forest Labs Image Generation

Black Forest Labs Image Generation

Black Forest Labs는 FLUX 모델로 최첨단 텍스트-이미지 생성을 제공해요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 Black Forest Labs FLUX 모델, 고품질 텍스트-이미지 생성
LiteLLM 라우트 black_forest_labs/
공급자 문서 Black Forest Labs API
지원 작업 /images/generations

설정 (Setup)

API 키

Black Forest Labs에서 API 키를 가져와요.

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

지원 모델 (Supported Models)

모델 이름 설명 가격
black_forest_labs/flux-pro-1.1 빠르고 신뢰할 수 있는 표준 생성 $0.04/이미지
black_forest_labs/flux-pro-1.1-ultra 초고해상도 (최대 4MP) $0.06/이미지
black_forest_labs/flux-dev 개발/오픈소스 변형 $0.025/이미지
black_forest_labs/flux-pro 원본 pro 모델 $0.05/이미지

이미지 생성 (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)

비동기 이미지 생성

import os
import asyncio
import litellm

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

async def generate_image():
    response = await litellm.aimage_generation(
        model="black_forest_labs/flux-pro-1.1",
        prompt="A futuristic city skyline at night",
    )
    print(response.data[0].url)

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

사용자 지정 크기 이미지 생성

import os
import litellm

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

# Generate with specific dimensions
response = litellm.image_generation(
    model="black_forest_labs/flux-pro-1.1",
    prompt="A majestic mountain landscape",
    size="1792x1024",  # Maps to width/height
)
print(response.data[0].url)

초고해상도 이미지 생성

import os
import litellm

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

# Generate ultra high-resolution image
response = litellm.image_generation(
    model="black_forest_labs/flux-pro-1.1-ultra",
    prompt="Detailed portrait of a fantasy character",
    size="2048x2048",  # Up to 4MP supported
    quality="hd",  # Maps to raw=True for natural look
)
print(response.data[0].url)

BFL 전용 파라미터 이미지 생성

import os
import litellm

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

# Generate with BFL-specific parameters
response = litellm.image_generation(
    model="black_forest_labs/flux-pro-1.1",
    prompt="A cute orange cat sitting on a windowsill",
    seed=42,  # For reproducible results
    output_format="png",  # png or jpeg
    safety_tolerance=2,  # 0-6, higher = more permissive
    prompt_upsampling=True,  # Enhance prompt for better results
)
print(response.data[0].url)

LiteLLM Proxy Server 사용법

1. config.yaml 설정

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: os.environ/LITELLM_MASTER_KEY

2. Proxy 서버 시작

litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000

3. 이미지 생성 요청

OpenAI SDK:

from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
    base_url="http://localhost:4000",
    api_key="sk-<your-litellm-api-key>"
)

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

cURL:

curl -X POST 'http://localhost:4000/v1/images/generations' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer ***" \
  -d '{
    "model": "flux-pro",
    "prompt": "A beautiful garden with colorful flowers",
    "size": "1024x1024"
  }'

지원 파라미터 (Supported Parameters)

OpenAI 호환 파라미터

파라미터 타입 설명 매핑
prompt string 생성할 이미지의 텍스트 설명 직접
model string 사용할 FLUX 모델 직접
size string 이미지 크기 (예: 1024x1024) width와 height로 매핑
n integer 이미지 수 (ultra 모델만, 최대 4) num_images로 매핑
quality string 자연스러운 느낌을 위한 hd ultra에서 raw=True로 매핑
response_format string url 또는 b64_json 직접

Black Forest Labs 전용 파라미터

파라미터 타입 설명 기본값
width integer 이미지 너비 (256-1920, 16의 배수) 1024
height integer 이미지 높이 (256-1920, 16의 배수) 1024
aspect_ratio string width/height 대안 (예: 16:9, 1:1) -
seed integer 재현 가능한 결과용 시드 랜덤
output_format string 출력 형식: png 또는 jpeg png
safety_tolerance integer 안전 필터 허용도 (0-6, 높을수록 관대) 2
prompt_upsampling boolean 더 나은 결과를 위해 프롬프트 향상 false

Ultra 모델 전용 파라미터

파라미터 타입 설명 기본값
raw boolean 더 자연스러운, 덜 인위적인 느낌을 위한 raw 모드 false
num_images integer 생성할 이미지 수 (1-4) 1

동작 방식 (How It Works)

Black Forest Labs는 폴링 기반 API를 사용해요:

  1. 요청 제출: LiteLLM이 프롬프트를 BFL로 전송
  2. Task ID 획득: BFL이 task ID와 폴링 URL 반환
  3. 결과 폴링: LiteLLM이 이미지가 준비될 때까지 자동 폴링
  4. 결과 반환: 생성된 이미지 URL 반환

이 폴링은 LiteLLM이 자동으로 처리하므로, image_generation()을 호출하기만 하면 결과를 얻을 수 있어요.

시작하기 (Getting Started)

  1. Black Forest Labs에서 계정 만들기
  2. 대시보드에서 API 키 가져오기
  3. BFL_API_KEY 환경 변수 설정하기
  4. 지원되는 모델과 함께 litellm.image_generation() 사용하기

더 알아보기 (Learn more)