-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-image.py
More file actions
64 lines (52 loc) · 1.86 KB
/
Copy pathgenerate-image.py
File metadata and controls
64 lines (52 loc) · 1.86 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
59
60
61
62
63
64
#!/usr/bin/env python3
"""
AIGate API — Generate Image (Python)
Docs: https://aigatecloud.com/docs/
Install: pip install requests python-dotenv
Run: python examples/generate-image.py
"""
import os
import sys
import requests
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv("AIGATE_KEY", "sk-aigate-YOUR_KEY_HERE")
BASE_URL = os.getenv("AIGATE_BASE_URL", "https://api.aigatecloud.com/v1")
def generate_image(prompt: str, aspect_ratio: str = "9:16", use_case: str = "viral_background", style: str = "luxury") -> dict:
resp = requests.post(
f"{BASE_URL}/generate/image",
json={
"prompt": prompt,
"aspect_ratio": aspect_ratio,
"use_case": use_case,
"style": style,
},
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
timeout=60,
)
data = resp.json()
if not resp.ok or not data.get("ok"):
error = data.get("error", f"HTTP {resp.status_code}")
if resp.status_code == 401:
print(f"Error: {error}")
print("→ Register free at https://aigatecloud.com to get a real API key.")
else:
print(f"Error: {error}")
sys.exit(1)
return data
if __name__ == "__main__":
result = generate_image(
prompt="luxury lifestyle, gold tones, aspirational mood, social media ready",
aspect_ratio="9:16",
use_case="viral_background",
style="luxury",
)
asset = result["asset"]
print("✓ Image generated!")
print(f" Source: {result['source']} ({result['provider']})")
print(f" URL: {asset['url']}")
print(f" Size: {asset.get('width', '?')}×{asset.get('height', '?')}")
print(f" Credits: −{result['credits_charged']} (balance: {result['credits_balance']})")