Image Generation API Reference
Complete reference for the BrilliantAI Image Generation API.
Create Image
Generates an image from a text prompt using BrilliantAI's powerful glimmer-v1
model.
Endpoint
POST https://api.brilliantai.co/images/generate
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
model | string | Yes | Model ID to use for image generation (e.g., glimmer-v1) |
prompt | string | Yes | Description of the desired image |
aspect_ratio | string | No | Aspect ratio of the generated image (square, portrait, landscape). Default: square. |
image_format | string | No | Output format for the image (png, jpg, webp). Default: webp. |
seed | integer | No | Random seed for reproducibility |
Python SDK Reference
Initialize the Client
BrilliantAI(api_key=None, base_url="https://api.brilliantai.co", timeout=1200)
Creates a new client instance.
Parameter | Type | Required | Description |
---|---|---|---|
api_key | Optional[str] | No | API key for authentication. If not provided, uses the BRILLIANTAI_API_KEY environment variable. |
base_url | str | No | Base URL for API requests. Default is https://api.brilliantai.co. |
timeout | int | No | Request timeout in seconds. Default is 1200 (20 minutes). |
Generate an Image
generate_image(model, prompt, aspect_ratio=AspectRatio.SQUARE, image_format=ImageFormat.WEBP, seed=None)
Generate an Image python Copy Edit generate_image(model, prompt, aspect_ratio=AspectRatio.SQUARE, image_format=ImageFormat.WEBP, seed=None)
Generates an image based on the provided prompt and settings.
Parameter | Type | Required | Description |
---|---|---|---|
model | str | Yes | Model identifier (e.g., "glimmer-v1" ). |
prompt | str | Yes | Text prompt describing the desired image. |
aspect_ratio | BrilliantAI.AspectRatio | No | Aspect ratio (AspectRatio.SQUARE , AspectRatio.PORTRAIT , AspectRatio.LANDSCAPE ). Default: AspectRatio.SQUARE . |
image_format | BrilliantAI.ImageFormat | No | Image format (ImageFormat.PNG , ImageFormat.JPG , ImageFormat.WEBP ). Default: ImageFormat.WEBP . |
seed | Optional[int] | No | Seed value for reproducibility. |
Example Request
Python Example
from brilliantai import BrilliantAI
import os
client = BrilliantAI(
api_key=os.environ.get("BRILLIANTAI_API_KEY", "your-api-key")
)
image = client.generate_image(
model="glimmer-v1",
prompt="A futuristic city skyline at sunset",
aspect_ratio=BrilliantAI.AspectRatio.LANDSCAPE,
image_format=BrilliantAI.ImageFormat.PNG,
seed=123
)
print(f"Generated image URL: {image.url}")
# Save the generated image locally
image.save("city_sunset") # Saves as "city_sunset.png"
JavaScript Example
const url = "https://api.brilliantai.co/images/generate";
const apiKey = "YOUR_API_KEY_HERE";
const payload = {
model: "glimmer-v1",
prompt: "A futuristic city skyline at sunset",
aspect_ratio: "landscape",
image_format: "png",
seed: 123
};
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => {
data.images.forEach(image => {
console.log(`Generated image URL: ${image.url}`);
});
})
.catch(error => console.error('Error:', error));
cURL example
curl -X POST "https://api.brilliantai.co/images/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY_HERE" \
-d '{
"model": "glimmer-v1",
"prompt": "A futuristic city skyline at sunset",
"aspect_ratio": "landscape",
"image_format": "png",
"seed": 123
}'
Response format
Successful responses return JSON:
{
"id": "img-gen-123456",
"object": "image.generation",
"created": 1677652288,
"model": "glimmer-v1",
"images": [
{
"url": "https://cdn.brilliantai.co/images/generated/img-123.png",
"format": "png",
"aspect_ratio": "landscape"
}
]
}
Error Handling
try:
image = client.generate_image(
model="glimmer-v1",
prompt="A futuristic city skyline at sunset"
)
except brilliantai.APIError as e:
print(f"API Error: {e}")
except brilliantai.RateLimitError as e:
print(f"Rate Limit Error: {e}")
except brilliantai.APIConnectionError as e:
print(f"Connection Error: {e}")
Best Practices
-
Prompt Clarity
- Write descriptive prompts for best results.
- Include visual style and specific context.
-
Performance
- Utilize aspect ratios that match your app layout.
- Cache images when possible to reduce costs.
-
Reproducibility
- Use seeds for predictable and repeatable outputs.
Next Steps
- Try image generation in our no-code Studio
- Explore available image models
- Learn prompt engineering tips