Image Generation
Generate images from text prompts using the images endpoint.
Overview
The image generation endpoint creates images from text descriptions. It follows the OpenAI images API format and supports multiple image generation models across providers.
POST https://api.universal-ai.dev/v1/images/generationsRequest
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer YOUR_API_KEY |
Content-Type | Yes | application/json |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | No | The image model to use (e.g., dall-e-3, cf/stable-diffusion-xl). Defaults to dall-e-3. |
prompt | string | Yes | A text description of the image to generate. Be specific and descriptive for best results. |
n | integer | No | Number of images to generate. Default: 1. Max depends on the model. |
size | string | No | Image dimensions. Options vary by model. Common values: 1024x1024, 1024x1792, 1792x1024. Default: 1024x1024. |
quality | string | No | Image quality. standard or hd (for supported models). Default: standard. |
response_format | string | No | Format of the returned image: url (default) or b64_json. |
style | string | No | Image style: natural or vivid (DALL-E 3 only). Default: vivid. |
Example Request
curl https://api.universal-ai.dev/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "A serene mountain lake at sunset with pine trees reflected in still water, photorealistic style",
"n": 1,
"size": "1024x1024",
"quality": "hd"
}'Response
{
"created": 1700000000,
"data": [
{
"url": "https://api.universal-ai.dev/v1/files/img_abc123.png",
"revised_prompt": "A serene mountain lake at sunset, with tall pine trees perfectly reflected in the crystal-clear, still water. The sky is painted in warm hues of orange, pink, and purple."
}
]
}Response Fields
| Field | Type | Description |
|---|---|---|
created | integer | Unix timestamp of when the image was generated. |
data | array | Array of generated image objects. |
data[].url | string | URL of the generated image (when response_format is url). |
data[].b64_json | string | Base64-encoded image data (when response_format is b64_json). |
data[].revised_prompt | string | The prompt as revised by the model (DALL-E 3 may refine your prompt). |
SDK Examples
Python:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.universal-ai.dev/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="A futuristic city skyline with flying cars and neon lights",
n=1,
size="1024x1024"
)
image_url = response.data[0].url
print(f"Image URL: {image_url}")JavaScript / TypeScript:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.universal-ai.dev/v1",
});
const response = await client.images.generate({
model: "dall-e-3",
prompt: "A futuristic city skyline with flying cars and neon lights",
n: 1,
size: "1024x1024",
});
console.log(`Image URL: ${response.data[0].url}`);Available Models
| Model ID | Provider | Sizes | Description |
|---|---|---|---|
dall-e-3 | OpenAI | 1024x1024, 1024x1792, 1792x1024 | High-quality image generation with prompt understanding |
dall-e-2 | OpenAI | 256x256, 512x512, 1024x1024 | Faster generation, multiple images per request |
cf/stable-diffusion-xl | Cloudflare | 1024x1024 | Stable Diffusion XL on Workers AI (low cost) |
cf/stable-diffusion-v1-5 | Cloudflare | 512x512 | Stable Diffusion 1.5 on Workers AI |
flux-bfl/flux-1.1-pro | Black Forest Labs | 1024x1024, custom | FLUX 1.1 Pro for high-fidelity generation |
Tips for Better Results
- Be specific — describe the subject, style, lighting, and composition. "A golden retriever sitting in a sunny meadow, oil painting style" produces better results than "a dog."
- Specify style — include artistic direction like "photorealistic," "watercolor," "digital art," or "pencil sketch."
- Use
quality: "hd"— for DALL-E 3, HD mode produces images with finer detail and greater consistency. - Try different models — each model has different strengths. FLUX excels at photorealism, DALL-E 3 at creative interpretation, and Stable Diffusion at stylized art.