-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
54 lines (46 loc) · 1.58 KB
/
search.php
File metadata and controls
54 lines (46 loc) · 1.58 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
<?php
/**
* AIGate API — Search Asset Library Example
* Searching is FREE (0 credits). Download/use costs credits.
* Docs: https://aigatecloud.com/docs/
*/
$apiKey = getenv('AIGATE_KEY') ?: 'sk-aigate-YOUR_KEY_HERE';
$baseUrl = getenv('AIGATE_BASE_URL') ?: 'https://api.aigatecloud.com/v1';
$params = http_build_query([
'q' => 'luxury gold lifestyle',
'type' => 'image', // image | video
'aspect_ratio' => '9:16',
'use_case' => 'viral_background',
'limit' => 10,
]);
$ch = curl_init($baseUrl . '/search?' . $params);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($body, true);
if (!$result || !($result['ok'] ?? false)) {
echo "Error ($status): " . ($result['error'] ?? $body) . PHP_EOL;
if ($status === 401) {
echo "→ Register free at https://aigatecloud.com to get a real API key." . PHP_EOL;
}
exit(1);
}
$assets = $result['assets'] ?? [];
echo "Found " . count($assets) . " assets (total: " . ($result['total'] ?? '?') . ")" . PHP_EOL;
foreach ($assets as $i => $a) {
echo sprintf(
" [%d] %s | %s | %s\n %s\n",
$i + 1,
$a['aspect_ratio'],
$a['use_case'],
implode(', ', array_slice($a['tags'] ?? [], 0, 4)),
$a['thumbnail_url'] ?? $a['url']
);
}
echo PHP_EOL . "Note: Using an asset via /generate/image still deducts 10 credits." . PHP_EOL;