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/generations

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer YOUR_API_KEY
Content-TypeYesapplication/json

Body Parameters

ParameterTypeRequiredDescription
modelstringNoThe image model to use (e.g., dall-e-3, cf/stable-diffusion-xl). Defaults to dall-e-3.
promptstringYesA text description of the image to generate. Be specific and descriptive for best results.
nintegerNoNumber of images to generate. Default: 1. Max depends on the model.
sizestringNoImage dimensions. Options vary by model. Common values: 1024x1024, 1024x1792, 1792x1024. Default: 1024x1024.
qualitystringNoImage quality. standard or hd (for supported models). Default: standard.
response_formatstringNoFormat of the returned image: url (default) or b64_json.
stylestringNoImage 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

FieldTypeDescription
createdintegerUnix timestamp of when the image was generated.
dataarrayArray of generated image objects.
data[].urlstringURL of the generated image (when response_format is url).
data[].b64_jsonstringBase64-encoded image data (when response_format is b64_json).
data[].revised_promptstringThe 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 IDProviderSizesDescription
dall-e-3OpenAI1024x1024, 1024x1792, 1792x1024High-quality image generation with prompt understanding
dall-e-2OpenAI256x256, 512x512, 1024x1024Faster generation, multiple images per request
cf/stable-diffusion-xlCloudflare1024x1024Stable Diffusion XL on Workers AI (low cost)
cf/stable-diffusion-v1-5Cloudflare512x512Stable Diffusion 1.5 on Workers AI
flux-bfl/flux-1.1-proBlack Forest Labs1024x1024, customFLUX 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.