Class FalImageProvider

Image generation provider connecting to the Fal.ai serverless platform.

Implements the queue-based submit-then-poll pattern: a generation request returns a request ID immediately, and the provider polls the status endpoint until completion or timeout.

Implements

Example

const provider = new FalImageProvider();
await provider.initialize({ apiKey: process.env.FAL_API_KEY! });

const result = await provider.generateImage({
modelId: 'fal-ai/flux/dev',
prompt: 'A photorealistic astronaut riding a horse on Mars',
});
console.log(result.images[0].url);

Implements

Constructors

Methods

  • Initialize the provider with API credentials and optional configuration.

    Parameters

    • config: Record<string, unknown>

      Configuration object. Must include apiKey.

    Returns Promise<void>

    Throws

    If apiKey is missing or empty.

    Example

    await provider.initialize({ apiKey: 'fal_xxx' });
    
  • Generate an image using the Fal.ai queue API.

    Submits the generation task to the queue, then polls the status endpoint until the result is ready or the timeout is reached.

    Parameters

    Returns Promise<ImageGenerationResult>

    The generated image result with URL(s).

    Throws

    If the provider is not initialized.

    Throws

    If the API returns an error or times out.

    Example

    const result = await provider.generateImage({
    modelId: 'fal-ai/flux/dev',
    prompt: 'A serene Japanese garden in autumn',
    n: 2,
    });

Properties

providerId: "fal" = 'fal'

Inherit Doc

isInitialized: boolean = false

Inherit Doc

defaultModelId?: string

Inherit Doc