1. Go to this page and download the library: Download marceloeatworld/falai-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marceloeatworld / falai-php example snippets
use MarceloEatWorld\FalAI\FalAI;
$fal = new FalAI('your-api-key');
// Synchronous execution
$result = $fal->run('fal-ai/flux/schnell', [
'prompt' => 'a sunset over mountains',
'image_size' => 'landscape_16_9',
]);
$images = $result->json('images');
// Submit a job
$job = $fal->queue->submit('fal-ai/flux/schnell', [
'prompt' => 'a sunset over mountains',
]);
echo $job->requestId;
// Check status
$status = $fal->queue->status('fal-ai/flux/schnell', $job->requestId);
echo $status->status->value; // IN_QUEUE, IN_PROGRESS, COMPLETED
echo $status->queuePosition; // position in queue (if queued)
// Get result when completed
$result = $fal->queue->result('fal-ai/flux/schnell', $job->requestId);
$images = $result->json('images');
// Cancel a job
$fal->queue->cancel('fal-ai/flux/schnell', $job->requestId);
use MarceloEatWorld\FalAI\Data\QueueStatus;
$result = $fal->queue->subscribe('fal-ai/flux/schnell', [
'prompt' => 'a sunset over mountains',
], pollInterval: 500, timeout: 300, requestTimeout: 120, onStatus: function (QueueStatus $status) {
echo "Status: {$status->status->value}\n";
foreach ($status->logs as $log) {
echo " {$log['message']}\n";
}
});
$images = $result->json('images');
$job = $fal->queue->submit('fal-ai/flux/schnell', [
'prompt' => 'a sunset over mountains',
], webhook: 'https://your.app/webhook');
$this->app->singleton(\MarceloEatWorld\FalAI\FalAI::class, function () {
return new \MarceloEatWorld\FalAI\FalAI(config('services.falai.api_key'));
});
use MarceloEatWorld\FalAI\FalAI;
public function generate(FalAI $fal)
{
$result = $fal->queue->subscribe('fal-ai/flux/schnell', [
'prompt' => 'A mountain landscape',
]);
return $result->json('images');
}