1. Go to this page and download the library: Download cjmellor/fal-ai-laravel 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/ */
cjmellor / fal-ai-laravel example snippets
use Cjmellor\FalAi\Facades\FalAi;
$response = FalAi::model('fal-ai/flux/schnell')
->prompt('A beautiful sunset over mountains')
->imageSize('landscape_4_3')
->run();
$requestId = $response->requestId;
$response = FalAi::model('fal-ai/flux/dev')
->prompt('A detailed portrait')
->queue() // Optional - queue is the default
->run();
// Returns immediately with request_id
$requestId = $response->requestId;
$response = FalAi::model('fal-ai/flux/schnell')
->prompt('A quick sketch')
->sync()
->run();
// Returns the complete result
$images = $response->json()['images'];
// Check status
$status = FalAi::driver('fal')->status($requestId, 'fal-ai/flux/dev');
if ($status->json()['status'] === 'COMPLETED') {
// Get the result
$result = FalAi::driver('fal')->result($requestId, 'fal-ai/flux/dev');
$images = $result->json()['images'];
}
// Cancel a queued request
FalAi::driver('fal')->cancel($requestId, 'fal-ai/flux/dev');
$response = FalAi::model('fal-ai/flux/schnell')
->prompt('A fox in a forest')
->run();
$response->requestId; // Request ID
$response->statusUrl; // URL to check status
$response->responseUrl; // URL to get result
$response->cancelUrl; // URL to cancel
$stream = FalAi::model('fal-ai/flux/schnell')
->prompt('A dancing robot')
->stream();
// Process the stream response
$stream->getResponse();
$response = Ai::driver('replicate')
->model('stability-ai/sdxl')
->prompt('A landscape')
->run();
// Poll for completion
$status = Ai::driver('replicate')->status($response->id);
// Status helpers
$status->isRunning(); // starting or processing
$status->isSucceeded(); // completed successfully
$status->isFailed(); // failed
$status->isCanceled(); // canceled
$status->isTerminal(); // any final state
// Get result when complete
if ($status->isSucceeded()) {
$output = $status->output;
}
$prediction = Ai::driver('replicate')
->deployment('owner/my-deployment')
->with(['prompt' => 'A sunset over mountains'])
->webhook('https://example.com/webhook')
->run();
// Use prediction ID with standard status/result methods
$status = Ai::driver('replicate')->status($prediction->id);