Skip to main content

Overview

FalImageGenService provides high-speed image generation capabilities using fal’s optimized Stable Diffusion XL models. It supports various image sizes, formats, and generation parameters with a focus on fast inference and low-latency image creation.

Installation

To use fal image generation services, install the required dependencies:
pip install "pipecat-ai[fal]"

Prerequisites

fal Account Setup

Before using fal image generation services, you need:
  1. fal Account: Sign up at fal Platform
  2. API Key: Generate an API key from your account dashboard
  3. Model Selection: Choose from available fast SDXL models
  4. HTTP Session: Configure aiohttp session for image downloading

Required Environment Variables

  • FAL_KEY: Your fal API key for authentication

Configuration

params
InputParams
required
Input parameters for image generation configuration. See InputParams below.
aiohttp_session
aiohttp.ClientSession
required
HTTP client session for downloading generated images.
model
str
default:"fal-ai/fast-sdxl"
The fal model to use for image generation.
key
str
default:"None"
Optional API key for fal. If provided, sets the FAL_KEY environment variable.

InputParams

ParameterTypeDefaultDescription
seedintNoneRandom seed for reproducible generation. If None, uses a random seed.
num_inference_stepsint8Number of inference steps for generation.
num_imagesint1Number of images to generate.
image_sizestr | dict"square_hd"Image dimensions as a string preset or dict with width/height keys.
expand_promptboolFalseWhether to automatically expand/enhance the prompt.
enable_safety_checkerboolTrueWhether to enable content safety filtering.
formatstr"png"Output image format.

Usage

Basic Setup

import aiohttp
from pipecat.services.fal import FalImageGenService

async with aiohttp.ClientSession() as session:
    image_gen = FalImageGenService(
        params=FalImageGenService.InputParams(
            image_size="landscape_16_9",
        ),
        aiohttp_session=session,
        key=os.getenv("FAL_KEY"),
    )

With Custom Parameters

image_gen = FalImageGenService(
    params=FalImageGenService.InputParams(
        image_size={"width": 1024, "height": 768},
        num_inference_steps=12,
        seed=42,
        enable_safety_checker=True,
    ),
    aiohttp_session=session,
    model="fal-ai/fast-sdxl",
)

Notes

  • Environment variable: If the key constructor parameter is provided, it sets the FAL_KEY environment variable automatically.
  • HTTP session required: You must provide an aiohttp.ClientSession for downloading the generated images from fal’s URLs.
  • Image size presets: The image_size parameter accepts string presets (e.g., "square_hd", "landscape_16_9") or a dictionary with explicit width and height values.