Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/fal/llms.txt

Use this file to discover all available pages before exploring further.

FalImageModel submits a synchronous POST request to {baseUrl}/{modelId} (defaulting to https://fal.run/{modelId}) and returns an ImageResponse containing one or more ImageData objects. Each ImageData exposes the url of the generated image and its mimeType. Because the request is synchronous, run() blocks until fal.ai has finished generating the image and returns the result in a single call.

Basic Usage

use AiSdk\Generate;
use AiSdk\Fal;

$result = Generate::image()
    ->model(Fal::model('fal-ai/flux/schnell'))
    ->prompt('A minimal desk lamp on a white background.')
    ->run();

echo $result->images[0]->url;

Request Parameters

The following fields are assembled into the JSON body sent to fal.ai. Standard request properties are mapped automatically; any extra fal-specific parameters can be forwarded via provider options.
FieldTypeSourceDescription
promptstring$request->promptThe text prompt describing the image to generate.
num_imagesint$request->countNumber of images to generate.
image_sizestring$request->sizeDesired image size (e.g. square_hd, landscape_4_3). Only sent when size is set.
aspect_ratiostring$request->aspectRatioDesired aspect ratio (e.g. 16:9). Only sent when aspectRatio is set.
seedint$request->seedSeed for reproducible generation. Only sent when seed is not null.
Additional fields from $request->providerOptionsFor('fal') are merged into the body last, so they can override or extend any of the above.

Response

generate() returns an ImageResponse with an images array of ImageData objects. Each element has:
  • url (string) — the publicly accessible URL of the generated image, taken from images[*].url in the fal.ai response.
  • mimeType (string) — taken from images[*].content_type; defaults to image/png when the API omits it.
$result = Generate::image()
    ->model(Fal::model('fal-ai/flux/schnell'))
    ->prompt('A minimal desk lamp on a white background.')
    ->run();

foreach ($result->images as $image) {
    echo $image->url . PHP_EOL;      // https://cdn.fal.ai/…
    echo $image->mimeType . PHP_EOL; // image/png
}
An InvalidResponseException is thrown when the API response contains an empty images array. This can happen if the model rejects the prompt or the request payload is malformed.

Provider Options

Pass fal-specific parameters that are not part of the standard request interface using providerOptions(). These are merged into the request body and can override any automatically mapped field.
$result = Generate::image()
    ->model(Fal::model('fal-ai/flux/schnell'))
    ->prompt('A sunset.')
    ->providerOptions('fal', ['output_format' => 'jpeg'])
    ->run();

Build docs developers (and LLMs) love