PHP code example of marceloeatworld / falai-php

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


composer 

use MarceloEatWorld\FalAI\FalAI;
use MarceloEatWorld\FalAI\Data\GenerationData;

// config/services.php
'falai' => [
    'api_key' => env('FAL_API_KEY'),
],

// app/Providers/AppServiceProvider.php
public function register()
{
    $this->app->bind(FalAI::class, function () {
        return new FalAI(
            apiKey: config('services.falai.api_key'),
        );
    });
}

$falAI->generations()->withWebhook('https://www.example.com/webhook')->create($model, $input);
$data->requestId; // bf1bb655-9027-4d01-ac38-f85e0cb007dc

use MarceloEatWorld\FalAI\FalAI;
use MarceloEatWorld\FalAI\Data\GenerationData;

$model = 'fal-ai/modelyouwant';
$input = [
    "image_url" => "https://example.com/image.png",
    "prompt" => "A tender moment between the newlyweds, capturing their happiness with a natural background and soft light.",
    "negative_prompt" => "nsfw, lowres, bad anatomy",
    "seed" => 42
];

$data = $falAI->generations()->create($model, $input);
$data->requestId; // bf1bb655-9027-4d01-ac38-f85e0cb007dc

use MarceloEatWorld\FalAI\FalAI;
use MarceloEatWorld\FalAI\Data\GenerationData;

// Replace 'workflows/youraccount/fantasy-character-generator' with your actual workflow ID
$workflowId = 'workflows/youraccount/fantasy-character-generator';

// Replace 'comfy/youraccount/fantasy-character-generator' with your actual ComfyUI ID
$workflowId = 'comfy/youraccount/fantasy-character-generator';

$input = [
    'input' => [
        'character_description' => 'A brave elven warrior with long, flowing hair and a glowing magical sword.',
        'seed' => 42,
    ],
];

$data = $falAI->generations()->withWebhook($webhookUrl)->workflow($workflowId, $input);
$data->requestId; // 5e8f1ab3-2c7d-4e9a-b5d6-8c3a1f9b04e7