OpenAI DALL-E Image Generation Guide
OpenAI DALL-E Image Generation API: Complete Guide
The DALL-E API allows you to generate, edit, and create variations of images using text prompts. DALL-E 3 produces highly detailed, photorealistic images and can accurately render text, making it suitable for marketing materials, product mockups, illustrations, and creative projects.
Available Models and Capabilities
- DALL-E 3 — Latest model with best quality, text rendering, and prompt following. Supports 1024x1024, 1024x1792, 1792x1024.
- DALL-E 2 — Older model, supports editing and variations. Supports 256x256, 512x512, 1024x1024.
Generate an Image (Python)
from openai import OpenAI
client = OpenAI(base_url="https://claude4u.com/v1")
response = client.images.generate(
model="dall-e-3",
prompt="A serene Japanese garden in autumn with a wooden bridge over a koi pond, golden maple leaves falling, watercolor style",
size="1024x1024",
quality="standard",
n=1
)
image_url = response.data[0].url
print(f"Image URL: {image_url}")
# The revised prompt (DALL-E 3 may enhance your prompt)
revised_prompt = response.data[0].revised_prompt
print(f"Revised prompt: {revised_prompt}")
Generate an Image (Node.js)
import OpenAI from 'openai';
const client = new OpenAI({ baseURL: 'https://claude4u.com/v1' });
const response = await client.images.generate({
model: 'dall-e-3',
prompt: 'A futuristic city skyline at sunset with flying vehicles and neon lights, cyberpunk aesthetic',
size: '1792x1024',
quality: 'hd',
n: 1
});
console.log('Image URL:', response.data[0].url);
console.log('Revised prompt:', response.data[0].revised_prompt);
Image Quality Options
- standard — Default quality. Good for most uses. $0.040 per image (1024x1024).
- hd — Higher detail and consistency. $0.080 per image (1024x1024). Best for detailed scenes and professional use.
Image Sizes and Pricing (DALL-E 3)
- 1024x1024 — Square. $0.040 (standard) / $0.080 (HD)
- 1024x1792 — Portrait. $0.080 (standard) / $0.120 (HD)
- 1792x1024 — Landscape. $0.080 (standard) / $0.120 (HD)
Downloading and Saving Images
import requests
from openai import OpenAI
client = OpenAI(base_url="https://claude4u.com/v1")
response = client.images.generate(
model="dall-e-3",
prompt="A minimalist logo for a tech startup called 'NeuralFlow'",
size="1024x1024",
quality="hd",
n=1
)
# Download and save the image
image_url = response.data[0].url
img_data = requests.get(image_url).content
with open("generated_logo.png", "wb") as f:
f.write(img_data)
print("Image saved to generated_logo.png")
Get Image as Base64
response = client.images.generate(
model="dall-e-3",
prompt="An isometric illustration of a modern office workspace",
size="1024x1024",
response_format="b64_json",
n=1
)
import base64
image_bytes = base64.b64decode(response.data[0].b64_json)
with open("office.png", "wb") as f:
f.write(image_bytes)
Writing Effective Prompts
The quality of generated images depends heavily on your prompt. Follow these guidelines:
- Be specific — "A golden retriever playing fetch on a beach at sunset" beats "a dog"
- Specify style — Add art style: "watercolor", "photorealistic", "pixel art", "oil painting", "3D render"
- Describe composition — "close-up", "aerial view", "wide angle", "centered"
- Include lighting — "dramatic lighting", "soft natural light", "neon glow", "golden hour"
- Set mood — "peaceful", "dramatic", "whimsical", "dark and moody"
Tip: DALL-E 3 automatically enhances your prompts. If you want to control the exact output, add specificity to avoid unwanted embellishments. You can see the revised prompt in the response to understand what the model actually used.
Image Editing (DALL-E 2)
DALL-E 2 supports inpainting, where you mask a region and generate new content:
response = client.images.edit(
model="dall-e-2",
image=open("original.png", "rb"),
mask=open("mask.png", "rb"),
prompt="A fluffy orange cat sitting on the chair",
size="1024x1024",
n=1
)
print(response.data[0].url)
Warning: Image editing requires the input and mask to be square PNG images with the same dimensions. The mask must have transparent regions where you want new content generated. DALL-E 3 does not support editing or variations.
Image Variations (DALL-E 2)
response = client.images.create_variation(
model="dall-e-2",
image=open("original.png", "rb"),
size="1024x1024",
n=3
)
for i, img in enumerate(response.data):
print(f"Variation {i + 1}: {img.url}")
Content Policy and Limitations
- DALL-E will reject prompts that violate OpenAI's content policy
- Requests for real people's likenesses are blocked
- Violent, adult, or hateful content is not generated
- Generated images include C2PA metadata for provenance
Batch Image Generation
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="https://claude4u.com/v1")
async def generate_batch(prompts):
tasks = [
client.images.generate(
model="dall-e-3",
prompt=prompt,
size="1024x1024",
n=1
)
for prompt in prompts
]
results = await asyncio.gather(*tasks)
return [r.data[0].url for r in results]
prompts = [
"A mountain landscape at dawn",
"An underwater coral reef scene",
"A cozy library with warm lighting"
]
urls = asyncio.run(generate_batch(prompts))
for url in urls:
print(url)
Tip: claude4u.com supports the DALL-E image generation API with the same interface. By routing image generation through the relay, you benefit from automatic retry on failures and unified usage tracking alongside your text generation costs.
Get Started with 轻舟 AI
Stable, fast AI API relay — supports Claude, OpenAI, Gemini and more
Sign Up Free
轻舟 AI