Fal AI

Fal AI

Fal AI는 FLUX, Stable Diffusion, Imagen 등 최첨단 이미지 생성 모델에 빠르고 확장 가능한 접근을 제공해요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 Fal AI는 저지연으로 이미지 생성 모델을 대규모 실행하기 위한 최적화된 인프라 제공
LiteLLM 라우트 fal_ai/
공급자 문서 Fal AI Documentation
지원 작업 /images/generations

설정 (Setup)

API 키

fal.ai에서 API 키를 가져와요.

import os
# Set your Fal AI API key
os.environ["FAL_AI_API_KEY"] = "your-fal-api-key"

지원 모델 (Supported Models)

모델 이름 설명 문서
fal_ai/fal-ai/flux-pro/v1.1 FLUX Pro v1.1 - 속도와 품질의 균형 Docs
fal_ai/flux/schnell Flux Schnell - image_size 지원이 있는 저지연 생성 Docs
fal_ai/fal-ai/bytedance/seedream/v3/text-to-image ByteDance Seedream v3 - image_size 제어 텍스트-이미지 Docs
fal_ai/fal-ai/bytedance/dreamina/v3.1/text-to-image ByteDance Dreamina v3.1 - image_size 제어 텍스트-이미지 Docs
fal_ai/fal-ai/flux-pro/v1.1-ultra FLUX Pro v1.1 Ultra - 고품질 이미지 생성 Docs
fal_ai/fal-ai/imagen4/preview Google Imagen 4 - 최고 품질 모델 Docs
fal_ai/fal-ai/recraft/v3/text-to-image Recraft v3 - 여러 스타일 옵션 Docs
fal_ai/fal-ai/ideogram/v3 Ideogram v3 - 글자 중심 창의적 모델 (Balanced: $0.06/이미지) Docs
fal_ai/fal-ai/stable-diffusion-v35-medium Stable Diffusion v3.5 Medium Docs
fal_ai/bria/text-to-image/3.2 Bria 3.2 - 상업용 등급 생성 Docs

이미지 생성 (Image Generation)

기본 이미지 생성

import litellm
import os

# Set your API key
os.environ["FAL_AI_API_KEY"] = "your-fal-api-key"

# Generate an image
response = litellm.image_generation(
    model="fal_ai/fal-ai/flux-pro/v1.1-ultra",
    prompt="A serene mountain landscape at sunset with vibrant colors"
)
print(response.data[0].url)

Google Imagen 4 생성

import litellm
import os

os.environ["FAL_AI_API_KEY"] = "your-fal-api-key"

# Generate with Imagen 4
response = litellm.image_generation(
    model="fal_ai/fal-ai/imagen4/preview",
    prompt="A vintage 1960s kitchen with flour package on countertop",
    aspect_ratio="16:9",
    num_images=1,
)
print(response.data[0].url)

특정 스타일로 Recraft v3 생성

import litellm
import os

os.environ["FAL_AI_API_KEY"] = "your-fal-api-key"

# Generate with specific style
response = litellm.image_generation(
    model="fal_ai/fal-ai/recraft/v3/text-to-image",
    prompt="A red panda eating bamboo",
    style="realistic_image",
    image_size="landscape_4_3",
)
print(response.data[0].url)

비동기 이미지 생성

import litellm
import asyncio
import os

async def generate_image():
    os.environ["FAL_AI_API_KEY"] = "your-fal-api-key"
    response = await litellm.aimage_generation(
        model="fal_ai/fal-ai/stable-diffusion-v35-medium",
        prompt="A cyberpunk cityscape with neon lights",
        guidance_scale=7.5,
        num_inference_steps=50,
    )
    print(response.data[0].url)
    return response

asyncio.run(generate_image())

고급 파라미터 이미지 생성

import litellm
import os

os.environ["FAL_AI_API_KEY"] = "your-fal-api-key"

# Generate with advanced parameters
response = litellm.image_generation(
    model="fal_ai/fal-ai/flux-pro/v1.1-ultra",
    prompt="A majestic dragon soaring over mountains",
    n=2,
    size="1792x1024",  # Maps to aspect_ratio="16:9"
    seed=42,
    safety_tolerance="2",
    enhance_prompt=True,
)
for image in response.data:
    print(f"Generated image: {image.url}")

LiteLLM Proxy Server 사용법

1. config.yaml 설정

model_list:
  - model_name: flux-ultra
    litellm_params:
      model: fal_ai/fal-ai/flux-pro/v1.1-ultra
      api_key: os.environ/FAL_AI_API_KEY
      model_info:
        mode: image_generation
  - model_name: imagen4
    litellm_params:
      model: fal_ai/fal-ai/imagen4/preview
      api_key: os.environ/FAL_AI_API_KEY
      model_info:
        mode: image_generation
  - model_name: stable-diffusion
    litellm_params:
      model: fal_ai/fal-ai/stable-diffusion-v35-medium
      api_key: os.environ/FAL_AI_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

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

response = client.images.generate(
    model="flux-ultra",
    prompt="A beautiful sunset over the ocean",
    n=1,
    size="1024x1024",
)
print(response.data[0].url)

LiteLLM SDK:

import litellm

response = litellm.image_generation(
    model="litellm_proxy/imagen4",
    prompt="A cozy coffee shop interior",
    api_base="http://localhost:4000",
    api_key="sk-<your-litellm-api-key>",
)
print(response.data[0].url)

cURL:

curl --location 'http://localhost:4000/v1/images/generations' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ***" \
  --data '{
    "model": "stable-diffusion",
    "prompt": "A serene Japanese garden with cherry blossoms",
    "n": 1,
    "size": "1024x1024"
  }'

모델별 파라미터 사용

LiteLLM은 표준 파라미터를 넘어서는 추가 파라미터를 직접 Fal AI API로 전달해요. 모델별 파라미터를 요청에 전달하면 Fal AI로 전송돼요.

import litellm

# Any parameters beyond the standard ones are forwarded to Fal AI
response = litellm.image_generation(
    model="fal_ai/fal-ai/flux-pro/v1.1-ultra",
    prompt="A beautiful sunset",
    # Model-specific Fal AI parameters
    aspect_ratio="16:9",
    safety_tolerance="2",
    enhance_prompt=True,
    seed=42,
)

각 모델이 지원하는 전체 파라미터 목록은 문서를 참고하세요: FLUX Pro v1.1-ultra Parameters, Imagen 4 Parameters, Recraft v3 Parameters, Stable Diffusion v3.5 Parameters, Bria 3.2 Parameters.

지원 파라미터 (Supported Parameters)

모든 모델에서 동작하는 표준 OpenAI 호환 파라미터:

파라미터 타입 설명 기본값
prompt string 원하는 이미지의 텍스트 설명 필수
model string 사용할 Fal AI 모델 필수
n integer 생성할 이미지 수 (1-4) 1
size string 이미지 크기 (모델별 형식으로 매핑) 모델 기본값
api_key string Fal AI API 키 환경 변수

시작하기 (Getting Started)

  1. fal.ai에서 가입
  2. 계정 설정에서 API 키 가져오기
  3. FAL_AI_API_KEY 환경 변수 설정
  4. Fal AI 모델 갤러리에서 모델 선택
  5. LiteLLM으로 이미지 생성 시작

더 알아보기 (Learn more)