Skip to main content

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

ParameterTypeRequiredDescription
modelstringYesModel ID to use for image generation (e.g., glimmer-v1)
promptstringYesDescription of the desired image
aspect_ratiostringNoAspect ratio of the generated image (square, portrait, landscape). Default: square.
image_formatstringNoOutput format for the image (png, jpg, webp). Default: webp.
seedintegerNoRandom 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.

ParameterTypeRequiredDescription
api_keyOptional[str]NoAPI key for authentication. If not provided, uses the BRILLIANTAI_API_KEY environment variable.
base_urlstrNoBase URL for API requests. Default is https://api.brilliantai.co.
timeoutintNoRequest 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.

ParameterTypeRequiredDescription
modelstrYesModel identifier (e.g., "glimmer-v1").
promptstrYesText prompt describing the desired image.
aspect_ratioBrilliantAI.AspectRatioNoAspect ratio (AspectRatio.SQUARE, AspectRatio.PORTRAIT, AspectRatio.LANDSCAPE). Default: AspectRatio.SQUARE.
image_formatBrilliantAI.ImageFormatNoImage format (ImageFormat.PNG, ImageFormat.JPG, ImageFormat.WEBP). Default: ImageFormat.WEBP.
seedOptional[int]NoSeed 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

  1. Prompt Clarity

    • Write descriptive prompts for best results.
    • Include visual style and specific context.
  2. Performance

    • Utilize aspect ratios that match your app layout.
    • Cache images when possible to reduce costs.
  3. Reproducibility

    • Use seeds for predictable and repeatable outputs.

Next Steps