-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-video.php
More file actions
56 lines (49 loc) · 2.05 KB
/
generate-video.php
File metadata and controls
56 lines (49 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* AIGate API — Generate Video Example
* Requires: Starter plan or above ($9 one-time, 1,200 credits)
* Docs: https://aigatecloud.com/docs/
*
* Each video costs 100 credits.
* Free plan (100 credits total) cannot generate videos — upgrade at aigatecloud.com
*/
$apiKey = getenv('AIGATE_KEY') ?: 'sk-aigate-YOUR_KEY_HERE';
$baseUrl = getenv('AIGATE_BASE_URL') ?: 'https://api.aigatecloud.com/v1';
$payload = [
'prompt' => 'product showcase, rotating camera, clean white background, premium feel',
'aspect_ratio' => '9:16', // 9:16 | 16:9 | 1:1
'use_case' => 'ads_product',
'style' => 'cinematic',
'duration' => 5, // seconds (3–15)
];
$ch = curl_init($baseUrl . '/generate/video');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_TIMEOUT => 120, // video gen can take up to 60–90s
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($body, true);
if (!$result || !($result['ok'] ?? false)) {
$error = $result['error'] ?? $body;
echo "Error ($status): $error" . PHP_EOL;
if ($status === 403 || str_contains($error, 'plan')) {
echo "→ Video generation requires Starter plan or above." . PHP_EOL;
echo " Upgrade at: https://aigatecloud.com/#pricing" . PHP_EOL;
} elseif ($status === 401) {
echo "→ Register free at https://aigatecloud.com to get a real API key." . PHP_EOL;
}
exit(1);
}
echo "✓ Video generated!" . PHP_EOL;
echo " Source: " . $result['source'] . " (" . $result['provider'] . ")" . PHP_EOL;
echo " URL: " . $result['asset']['url'] . PHP_EOL;
echo " Duration: " . ($result['asset']['duration'] ?? '?') . "s" . PHP_EOL;
echo " Credits: −" . $result['credits_charged'] . " (balance: " . $result['credits_balance'] . ")" . PHP_EOL;