Image Generation
Generate high-quality images using selam-image-turbo, selam-image, and selam-image-pro models with access to 34+ state-of-the-art image generation models.
Overview
Selam API provides three image generation models that give you access to multiple state-of-the-art image generation providers. All models are OpenAI-compatible and support various image sizes and formats.
selam-image-turbo
Fast image generation available for all users including FREE tier. Perfect for quick prototyping and testing.
selam-image
Standard image generation with access to 34+ models including FLUX, Stable Diffusion, and more.
selam-image-pro
Premium image generation with priority access and higher quality outputs.
Information
Supported Image Sizes
All models support the following image sizes:
256x256Small square images
512x512Medium square images
1024x1024Large square images (default)
1792x1024Landscape images
1024x1792Portrait images
Response Formats
Images can be returned in two formats:
urlReturns a URL to the generated image (default). URLs expire after 1 hour.
b64_jsonReturns the image as a base64-encoded JSON string for immediate use.
Basic Example
Generate an image with a simple prompt:
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="your-api-key",
5 base_url="https://api.selamgpt.com/v1"
6)
7
8response = client.images.generate(
9 model="selam-image",
10 prompt="A serene landscape with mountains and a lake at sunset",
11 size="1024x1024",
12 n=1
13)
14
15image_url = response.data[0].url
16print(f"Generated image: {image_url}")Base64 Response Format
Get the image as base64-encoded data instead of a URL:
1import base64
2from openai import OpenAI
3
4client = OpenAI(
5 api_key="your-api-key",
6 base_url="https://api.selamgpt.com/v1"
7)
8
9response = client.images.generate(
10 model="selam-image",
11 prompt="A futuristic city at night",
12 size="1024x1024",
13 response_format="b64_json"
14)
15
16# Decode and save the image
17image_data = base64.b64decode(response.data[0].b64_json)
18with open("generated_image.png", "wb") as f:
19 f.write(image_data)Generating Multiple Images
Generate multiple variations of an image in a single request:
1from openai import OpenAI
2
3client = OpenAI(
4 api_key="your-api-key",
5 base_url="https://api.selamgpt.com/v1"
6)
7
8response = client.images.generate(
9 model="selam-image",
10 prompt="A cute robot playing with a cat",
11 size="1024x1024",
12 n=3 # Generate 3 variations
13)
14
15for i, image in enumerate(response.data):
16 print(f"Image {i+1}: {image.url}")Information
Direct Model Access
You can also specify a direct model instead of using the virtual selam-image models. We support 34+ image generation models including:
FLUX Models
flux-pro, flux-dev, flux-schnell
Stable Diffusion
sd-3.5-large, sd-3.5-turbo, sdxl
Playground
playground-v2.5
And More
30+ additional models available
1response = client.images.generate(
2 model="flux-pro", # Use a specific model
3 prompt="A magical forest with glowing mushrooms",
4 size="1024x1024"
5)Tip
selam-image-turbo, selam-image, or selam-image-pro for automatic model selection and load balancing. Use direct model names when you need a specific model's characteristics.Error Handling
Handle common errors when generating images:
1from openai import OpenAI, APIError, RateLimitError, AuthenticationError
2
3client = OpenAI(
4 api_key="your-api-key",
5 base_url="https://api.selamgpt.com/v1"
6)
7
8try:
9 response = client.images.generate(
10 model="selam-image",
11 prompt="A beautiful sunset",
12 size="1024x1024"
13 )
14 print(f"Generated: {response.data[0].url}")
15
16except RateLimitError as e:
17 print(f"Rate limit exceeded: {e}")
18 # Wait and retry
19
20except AuthenticationError as e:
21 print(f"Authentication failed: {e}")
22 # Check your API key
23
24except APIError as e:
25 print(f"API error: {e}")
26 # Handle other errorsBest Practices
Write Detailed Prompts
More detailed prompts generally produce better results. Include style, mood, lighting, and composition details.
Choose the Right Size
Use 1024x1024 for general purposes, 1792x1024 for landscapes, and 1024x1792 for portraits. Smaller sizes generate faster but with less detail.
Handle Rate Limits
Image generation has stricter rate limits than text. Implement exponential backoff and respect the rate limit headers.
Save Images Promptly
Image URLs expire after 1 hour. Download and save images to your own storage if you need them long-term, or use the base64 format.
Use Pro for Quality
For production applications or when quality is critical, use selam-image-pro for priority access and better outputs. Use selam-image-turbo for quick testing.
Related Resources
Was this page helpful?