跳至主要內容

Black Forest Labs 圖像生成

Black Forest Labs 使用其 FLUX 模型提供最先進的文字轉圖像生成。

概覽

屬性詳細資訊
說明用於高品質文字轉圖像生成的 Black Forest Labs FLUX 模型
LiteLLM 上的提供者路由black_forest_labs/
提供者文件Black Forest Labs API ↗
支援的操作/images/generations

設定

API 金鑰

import os

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

請從 Black Forest Labs 取得您的 API 金鑰。

支援的模型

模型名稱說明價格
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/張圖片

圖像生成

用法 - 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)

用法 - LiteLLM Proxy Server

1. 設定您的 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. 啟動 LiteLLM Proxy Server

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

# RUNNING on http://0.0.0.0:4000

3. 發出圖像生成請求

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)

支援的參數

OpenAI 相容參數

參數類型說明對應
promptstring要生成的圖像文字描述直接對應
modelstring要使用的 FLUX 模型直接對應
sizestring圖像尺寸(例如,1024x1024對應到 widthheight
ninteger圖像數量(僅 ultra 模型,最多 4 張)對應到 num_images
qualitystring用於營造自然外觀的 hdultra 時對應到 raw=True
response_formatstringurlb64_json直接對應

Black Forest Labs 特定參數

參數類型說明預設值
widthinteger圖像寬度(256-1920,16 的倍數)1024
heightinteger圖像高度(256-1920,16 的倍數)1024
aspect_ratiostring寬度/高度的替代選項(例如,16:91:1-
seedinteger用於重現結果的種子隨機
output_formatstring輸出格式:pngjpegpng
safety_toleranceinteger安全過濾器容忍度(0-6,越高 = 越寬鬆)2
prompt_upsamplingboolean增強提示詞以獲得更好結果false

Ultra 模型特定參數

參數類型說明預設值
rawboolean更原始的模式,呈現更自然、較少人工感的外觀false
num_imagesinteger要生成的圖像數量(1-4)1

運作方式

Black Forest Labs 使用輪詢式 API:

  1. 提交請求:LiteLLM 將您的提示詞傳送到 BFL
  2. 取得任務 ID:BFL 回傳任務 ID 和輪詢 URL
  3. 輪詢結果:LiteLLM 自動輪詢直到圖像就緒
  4. 回傳結果:回傳生成的圖像 URL

此輪詢由 LiteLLM 自動處理——您只需呼叫 image_generation() 並取得結果。

開始使用

  1. Black Forest Labs 建立帳號
  2. 從儀表板取得您的 API 金鑰
  3. 設定您的 BFL_API_KEY 環境變數
  4. 搭配任何支援的模型使用 litellm.image_generation()

其他資源