Skip to main content

PHP SDK

The official Vidiking PHP SDK. Requires PHP 8.1+.

Installation

composer require vidiai/sdk

Setup

<?php

use Vidiking\Client;

$client = new Client([
'apiKey' => getenv('VIDIKING_API_KEY'),
'sandbox' => false,
]);

Video Rendering

Render

$result = $client->render([
'timeline' => [
'background' => '#000000',
'tracks' => [
[
'clips' => [
[
'asset' => ['type' => 'title', 'text' => 'Hello World', 'style' => 'minimal', 'size' => 'large'],
'start' => 0,
'length' => 5,
],
],
],
],
],
'output' => ['format' => 'mp4', 'resolution' => 'hd'],
]);

echo "Job ID: " . $result->jobId . "\n";

Get Render Status

$job = $client->getRender($result->jobId);
echo $job->status; // QUEUED | PROCESSING | COMPLETE | FAILED
echo $job->url; // Available when COMPLETE

Poll Until Complete

$job = $client->pollJob($result->jobId, interval: 3, timeout: 300);
echo "Output: " . $job->url . "\n";

Stitch

$result = $client->stitch([
'clips' => [
['src' => 'https://example.com/intro.mp4'],
['src' => 'https://example.com/main.mp4', 'trim' => 5, 'length' => 30],
['src' => 'https://example.com/outro.mp4'],
],
'output' => ['format' => 'mp4', 'resolution' => 'hd'],
]);

Trim

$result = $client->trim([
'src' => 'https://example.com/video.mp4',
'start' => 10,
'length' => 20,
'output' => ['format' => 'mp4', 'resolution' => 'hd'],
]);

AI Features

Image Generation

$image = $client->ai->generateImage([
'prompt' => 'A mountain landscape at sunset',
'model' => 'flux',
'width' => 1920,
'height' => 1080,
]);

echo $image->url;

Video Generation

$result = $client->ai->generateVideo([
'prompt' => 'Aerial shot of ocean waves',
'model' => 'runway-gen4-turbo',
'duration' => 5,
]);

$job = $client->pollJob($result->jobId);
echo $job->url;

Voiceover

$voiceover = $client->ai->generateVoiceover([
'text' => 'Welcome to our product tour.',
'voice' => 'rachel',
'model' => 'elevenlabs-flash',
]);

echo $voiceover->url;

Templates

// List templates
$templates = $client->templates->list(['category' => 'marketing']);

// Render template
$result = $client->templates->render('tpl_promo_001', [
'merge_fields' => [
'headline' => 'Big Sale',
'product_image' => 'https://example.com/product.png',
],
'output' => ['format' => 'mp4', 'resolution' => 'hd'],
]);

Error Handling

use Vidiking\Exceptions\VidikingException;
use Vidiking\Exceptions\InsufficientFundsException;
use Vidiking\Exceptions\RateLimitException;

try {
$client->render([...]);
} catch (InsufficientFundsException $e) {
echo "Not enough balance: " . $e->getBalance() . "\n";
} catch (RateLimitException $e) {
echo "Rate limited. Retry after: " . $e->getRetryAfter() . "s\n";
} catch (VidikingException $e) {
echo "API error: " . $e->getCode() . " - " . $e->getMessage() . "\n";
}

Configuration

$client = new Client([
'apiKey' => 'your_api_key',
'sandbox' => false,
'baseUrl' => 'https://api.vidiking.com',
'timeout' => 30,
'maxRetries' => 3,
]);