PHP code example of flixly / sdk

1. Go to this page and download the library: Download flixly/sdk 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/ */

    

flixly / sdk example snippets


use Flixly\Flixly;
use Flixly\FlixlyError;

$flixly = new Flixly(['api_key' => getenv('FLIXLY_API_KEY')]);

try {
    $gen = $flixly->generateAndWait([
        'model'  => 'flux-dev',
        'prompt' => 'A cat in a top hat, oil painting style',
        'type'   => 'TEXT_TO_IMAGE',
        'input'  => ['aspect_ratio' => '1:1', 'resolution' => '1K'],
    ]);
    echo $gen['data']['output_url']; // cdn.flixly.ai URL
} catch (FlixlyError $e) {
    error_log("Flixly: {$e->getErrorCode()} {$e->getMessage()}");
}

$flixly->generate([
    'model'        => 'veo-3-fast',
    'prompt'       => 'Cinematic shot of mountains at dawn',
    'type'         => 'TEXT_TO_VIDEO',
    'webhook_url'  => 'https://example.com/flixly-webhook',
]);

$body      = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_FLIXLY_SIGNATURE'] ?? '';
$timestamp = $_SERVER['HTTP_X_FLIXLY_TIMESTAMP'] ?? '';

$valid = Flixly::verifyWebhookSignature(
    getenv('FLIXLY_WEBHOOK_SECRET'),
    $timestamp,
    $signature,
    $body  // raw body — do NOT json_decode + re-encode, that breaks the signature
);

if (!$valid) {
    http_response_code(401);
    exit;
}

$event = json_decode($body, true);
// $event['event']       => "generation.completed" or "generation.failed"
// $event['id']          => task id
// $event['output_url']  => cdn.flixly.ai URL on success

$res = $flixly->listModels();
print_r($res['rateLimit']);
// ['limit' => 60, 'remaining' => 42, 'resetAtSec' => 1735056000]

try {
    $flixly->generate(['model' => 'flux-dev', 'prompt' => 'hi']);
} catch (FlixlyError $e) {
    $rl = $e->getRateLimit();
    if ($e->getHttpStatus() === 429 && $rl !== null) {
        $wait = max(0, $rl['resetAtSec'] - time());
        sleep($wait);
        // retry
    }
}

$res = $flixly->chat([
    'model'    => 'gpt-5-4-mini',
    'messages' => [
        ['role' => 'user', 'content' => 'Explain async/await in one sentence.'],
    ],
]);

echo $res['data']['choices'][0]['message']['content'];

new Flixly([
    'api_key'    => 'flx_live_...',
    'base_url'   => 'https://www.flixly.ai',  // default
    'timeout_ms' => 120000,                   // default 2 minutes
]);