Spaces:
Sleeping
Sleeping
Image Generation API
This module provides endpoints for generating images using OpenAI's DALL-E model.
Endpoints
POST /api/v1/images/generate
Generate an image using OpenAI DALL-E.
Request Body:
{
"prompt": "A cute baby sea otter",
"size": "1024x1024",
"n": 1,
"model": "dall-e-3"
}
Response:
{
"success": true,
"message": "Image generated successfully",
"filename": "uuid-generated-filename.png"
}
GET /api/v1/images/download/{filename}
Download a generated image by filename.
Response: Binary image file (PNG format)
Configuration
Make sure to set your OpenAI API key in your environment variables:
OPENAI_API_KEY=your-openai-api-key-here
Usage Example
import requests
# Generate image
response = requests.post("http://localhost:8000/api/v1/images/generate", json={
"prompt": "A cute baby sea otter",
"size": "1024x1024"
})
result = response.json()
if result["success"]:
filename = result["filename"]
# Download the image
image_response = requests.get(f"http://localhost:8000/api/v1/images/download/{filename}")
with open(f"downloaded_{filename}", "wb") as f:
f.write(image_response.content)