Guide: Image Generation
Introduction
This guide explains how to use our API for generating images using various AI models. The API supports multiple providers including OpenAI's DALL-E and Stability AI's models.
Supported Models
For a complete list of available models, please refer to the Models section and filter by the image generation capability. Each model has specific features and limitations detailed in their respective documentation.
Basic Image Generation
Using Python
from openai import OpenAI
client = OpenAI(
api_key="sk-...",
base_url="https://api.platform.a15t.com/v1",
)
response = client.images.generate(
model="openai/dall-e-3",
prompt="a white siamese cat",
size="1024x1024",
quality="standard",
n=1,
)
print(response.data[0].url)
Using cURL
curl https://api.platform.a15t.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "openai/dall-e-3",
"prompt": "a white siamese cat",
"n": 1,
"size": "1024x1024"
}'
Configuration Options
OpenAI DALL-E Models
You can control the quality and size of generated images using specific parameters. The available options include:
Size: Various dimension options (e.g., "1024x1024")
Quality: "standard" or "hd"
For detailed specifications, please refer to the OpenAI Image Generation documentation.
Stability AI Models
Stability AI models support additional configuration options through the model_extensions
parameter:
curl -XPOST https://api.platform.a15t.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "amazon/stability/stable-image-core-v1",
"prompt": "bottle",
"model_extensions": {
"provider": "stability",
"seed": 1,
"image_format": "jpg",
"aspect_ratio": "1"
}
}'
For complete details about Stability AI options, see their API documentation.
Response Format
The API supports two response formats: URL and base64-encoded JSON.
URL Format
Returns a URL to the generated image. Please note:
- URLs are valid for 24 hours
- API key is required to fetch the image
Example usage:
curl https://api.platform.a15t.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "openai/dall-e-3",
"prompt": "a white siamese cat",
"response_format": "url"
}'
Base64 JSON Format
Returns the image data directly encoded in base64 format. Recommended when you want to:
- Store the image data locally
- Avoid URL expiration
- Handle image data directly in your application
Example usage:
curl https://api.platform.a15t.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "openai/dall-e-3",
"prompt": "a white siamese cat",
"response_format": "b64_json"
}'