Imagen 4
Imagen 4 is Google’s most advanced AI image generation model, creating detailed, photorealistic or abstract images from text prompts. It excels at fine details and accurate text, perfect for professional visuals like posters and presentations.
1import requests
2import json
3
4url = "https://api.segmind.com/v1/imagen-4"
5headers = {
6 "x-api-key": "YOUR_API_KEY",
7 "Content-Type": "application/json"
8}
9
10data = {
11 "prompt": "A cozy cabin in the snowy mountains at sunrise, soft warm light, ultra-detailed, cinematic atmosphere",
12 "negative_prompt": "blurry, pixelated",
13 "aspect_ratio": "4:3"
14}
15
16response = requests.post(url, headers=headers, json=data)
17
18if response.status_code == 200:
19 result = response.json()
20 print(json.dumps(result, indent=2))
21else:
22 print(f"Error: {response.status_code}")
23 print(response.text) 1import requests
2import json
3
4url = "https://api.segmind.com/v1/imagen-4"
5headers = {
6 "x-api-key": "YOUR_API_KEY",
7 "Content-Type": "application/json"
8}
9
10data = {
11 "prompt": "A cozy cabin in the snowy mountains at sunrise, soft warm light, ultra-detailed, cinematic atmosphere",
12 "negative_prompt": "blurry, pixelated",
13 "aspect_ratio": "4:3"
14}
15
16response = requests.post(url, headers=headers, json=data)
17
18if response.status_code == 200:
19 result = response.json()
20 print(json.dumps(result, indent=2))
21else:
22 print(f"Error: {response.status_code}")
23 print(response.text)API Endpoint
https://api.segmind.com/v1/imagen-4Parameters
promptrequiredstringDescribes the scene or subject. Try 'A serene mountain landscape at sunset' for scenic compositions.
"A cozy cabin in the snowy mountains at sunrise, soft warm light, ultra-detailed, cinematic atmosphere"aspect_ratiooptionalstringDetermines the image's shape. Choose '4:3' for photos or '16:9' for widescreen imagery.
"4:3""1:1""4:3""3:4""9:16""16:9"negative_promptoptionalstringSpecifies elements to avoid. Use 'blurry, pixelated' to enhance image clarity.
"blurry, pixelated"Response Type
Returns: Text/JSON
Common Error Codes
The API returns standard HTTP status codes. Detailed error messages are provided in the response body.
Bad Request
Invalid parameters or request format
Unauthorized
Missing or invalid API key
Forbidden
Insufficient permissions
Not Found
Model or endpoint not found
Insufficient Credits
Not enough credits to process request
Rate Limited
Too many requests
Server Error
Internal server error
Bad Gateway
Service temporarily unavailable
Timeout
Request timed out