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.

This guide walks through generating one asset for each supported modality — image, speech, transcription, and video — using the aisdk/fal provider. By the end you will have working PHP snippets for all four and a clear picture of how the provider fits into the PHP AI SDK’s Generate::* fluent API.
1

Install

Add the package to your project with Composer:
composer require aisdk/fal
2

Configure

Create a provider instance and pass your fal.ai API key:
use AiSdk\Fal;

$provider = Fal::create(['apiKey' => getenv('FAL_API_KEY')]);
If FAL_API_KEY is already set in your environment, you can omit the argument entirely. Both Fal::create() (with no arguments) and Fal::default() will read FAL_API_KEY automatically:
use AiSdk\Fal;

// Both of these read FAL_API_KEY from the environment automatically.
$provider = Fal::create();
// or simply use the lazy default instance:
$provider = Fal::default();
3

Generate an image

Pass a fal model route to Fal::model() and call Generate::image() with a prompt:
use AiSdk\Fal;
use AiSdk\Generate;

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

echo $result->images[0]->url;
// https://cdn.fal.ai/...
$result->images is an array of ImageData objects. Each entry exposes a url pointing to the generated image hosted on fal’s CDN.
4

Generate speech

Synthesize speech from text using a fal speech model. The provider fetches the audio bytes automatically and returns them in $result->audio->data:
use AiSdk\Fal;
use AiSdk\Generate;

$result = Generate::speech()
    ->model(Fal::model('fal-ai/minimax/speech-02-hd'))
    ->input('Hello world.')
    ->run();

// $result->audio->data contains the raw audio bytes.
file_put_contents('output.mp3', $result->audio->data);
5

Transcribe audio

Transcribe a remote audio file by passing its URL to audioUrl():
use AiSdk\Fal;
use AiSdk\Generate;

$result = Generate::transcription()
    ->model(Fal::model('fal-ai/wizper'))
    ->audioUrl('https://example.com/sample.mp3')
    ->run();

echo $result->transcript->text;
// "Hello world..."
6

Generate video (async)

Video generation is submitted to queue.fal.run and polled automatically until the job completes. Call Generate::video() exactly like the other modalities — the SDK handles queuing and polling behind the scenes:
use AiSdk\Fal;
use AiSdk\Generate;

$result = Generate::video()
    ->model(Fal::model('fal-ai/kling-video/v1/standard/text-to-video'))
    ->prompt('A sunrise over mountains.')
    ->run();

echo $result->video->url;
// https://cdn.fal.ai/...
The run() call blocks until the video is ready or the poll timeout is reached. Once complete, $result->video->url contains the URL of the rendered video.
Video polling behaviour (interval and maximum wait time) is configurable via the videoPollIntervalMs and videoPollTimeoutMs options. See Configuration Options for details.
Language (chat/completions) and embedding modalities are not supported by the fal provider. Attempting to use them will throw a NoSuchModelException.

Build docs developers (and LLMs) love