-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-image.js
More file actions
58 lines (51 loc) · 1.75 KB
/
Copy pathgenerate-image.js
File metadata and controls
58 lines (51 loc) · 1.75 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
57
58
/**
* AIGate API — Generate Image (JavaScript / Node.js / browser fetch)
* Docs: https://aigatecloud.com/docs/
*
* Node.js: node examples/generate-image.js
* Browser: copy the generateImage() function and call it directly
*/
const API_KEY = process.env.AIGATE_KEY || 'sk-aigate-YOUR_KEY_HERE';
const BASE_URL = process.env.AIGATE_BASE_URL || 'https://api.aigatecloud.com/v1';
async function generateImage(options = {}) {
const payload = {
prompt: options.prompt || 'luxury lifestyle, gold, rich aesthetic',
aspect_ratio: options.aspect_ratio || '9:16',
use_case: options.use_case || 'viral_background',
style: options.style || 'luxury',
};
const res = await fetch(`${BASE_URL}/generate/image`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
const data = await res.json();
if (!res.ok || !data.ok) {
const msg = data.error || `HTTP ${res.status}`;
if (res.status === 401) {
throw new Error(`${msg}\n→ Register free at https://aigatecloud.com`);
}
throw new Error(msg);
}
return data;
}
// --- Run ---
generateImage({
prompt: 'cinematic product shot, minimal white background, premium brand',
aspect_ratio: '16:9',
use_case: 'ads_product',
style: 'cinematic',
})
.then(result => {
console.log('✓ Image generated!');
console.log(` Source: ${result.source} (${result.provider})`);
console.log(` URL: ${result.asset.url}`);
console.log(` Credits: −${result.credits_charged} (balance: ${result.credits_balance})`);
})
.catch(err => {
console.error('Error:', err.message);
process.exit(1);
});