Theme
Calling DALL·E with Python
Image Generation API Guide
Feature Overview
The API provides three main features:
- 🎨 Text to Image Generation (DALL·E 3 and DALL·E 2)
- ✏️ Image Editing (DALL·E 2 only)
- 🔄 Image Variation Generation (DALL·E 2 only)
1. Image Generation
Basic Usage
from openai import OpenAI
client = OpenAI(
base_url="https://www.kkiai.com/v1",
api_key=key
)
response = client.images.generate(
model="dall-e-3",
prompt="a white siamese cat",
size="1024x1024",
quality="standard",
n=1,
)
image_url = response.data[0].urlParameter Description
Size Options: 1024x1024, 1024x1792, 1792x1024
Quality Options: standard (default), hd (DALL·E 3 exclusive)
Quantity Limits
:
- DALL·E 3: 1 image per request
- DALL·E 2: Up to 10 images per request
2. Image Editing (DALL·E 2)
Usage Example
from openai import OpenAI
client = OpenAI(
base_url="https://www.kkiai.com/v1",
api_key=key
)
response = client.images.edit((
model="dall-e-2",
image=open("sunlit_lounge.png", "rb"),
mask=open("mask.png", "rb"),
prompt="A sunlit indoor lounge area with a pool containing a flamingo",
n=1,
size="1024x1024"
)
image_url = response.data[0].urlRequirements
- 📝 Image and mask must be in PNG format
- 📏 Must be square images
- 💾 File size < 4MB
- ⚖️ Image and mask dimensions must be identical
3. Image Variation Generation (DALL·E 2)
Usage Example
from openai import OpenAI
client = OpenAI(
base_url="https://www.kkiai.com/v1",
api_key=key
)
response = client.images.create_variation(
model="dall-e-2",
image=open("corgi_and_cat_paw.png", "rb"),
n=1,
size="1024x1024"
)
image_url = response.data[0].urlTechnical Requirements
- 📝 PNG format
- 📏 Square images
- 💾 File size < 4MB
Prompt Tips
DALL·E 3 Features
- Automatic prompt optimization
- Prompt optimization can be controlled via special instructions:
I NEED to test how the tool works with extremely simple prompts.
DO NOT add any detail, just use it AS-IS:Important Notes
Content Moderation
- Strictly comply with content policies
- Violations will return an error
Image URLs
- Valid for 1 hour
- Optional Base64 format return