1. Go to this page and download the library: Download tristanfrn/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/ */
tristanfrn / falai-php example snippets
use Tristanfrn\FalAI\FalAI;
$falAI = new FalAI('your-api-key');
// Generate an image
$result = $falAI->generations()->create('fal-ai/recraft-v3', [
'prompt' => 'A beautiful landscape',
'negative_prompt' => 'low quality',
'image_size' => 'square_hd'
'seed' => '42'
]);
// Check generation status using requestId
$status = $falAI->generations()->checkStatus($result->requestId);
// Get final result when completed
$finalResult = $falAI->generations()->getResult($result->requestId);
// Use webhooks
$result = $falAI->generations()
->withWebhook('https://your-site.com/webhook')
->create('fal-ai/recraft-v3', [
'prompt' => 'A serene lake'
'seed' => '42'
]);
// Cancel a generation using requestId
$cancelled = $falAI->generations()->cancel($result->requestId);
// Store the requestId after creation
$requestId = $result->requestId;
// Later, check status
$status = $falAI->generations()->checkStatus($requestId);
if ($status->status === 'COMPLETED') {
// Get the final result
$finalResult = $falAI->generations()->getResult($requestId);
// Access the generated images
$images = $finalResult->payload['images'] ?? [];
}
'falai' => [
'api_key' => env('FAL_API_KEY'),
],
public function register()
{
$this->app->singleton(FalAI::class, function () {
return new FalAI(config('services.falai.api_key'));
});
}
use Tristanfrn\FalAI\FalAI;
public function generate(FalAI $falAI)
{
$result = $falAI->generations()->create('fal-ai/recraft-v3', [
'prompt' => 'A mountain landscape'
'seed' => '42'
]);
// Store requestId for later use
$requestId = $result->requestId;
}
public function checkStatus(FalAI $falAI, string $requestId)
{
return $falAI->generations()->checkStatus($requestId);
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.