11# Image Generation OpenAPI Server
22
3- Production-ready OpenAPI server for AI image generation with LiteLLM proxy integration ( cost tracking) and direct API fallback support for OpenAI DALL-E and Google Gemini models .
3+ OpenAPI server for AI image generation and editing. Supports LiteLLM proxy (for cost tracking) and direct API access to OpenAI and Google Gemini.
44
55## Features
66
7- - ** LiteLLM Integration** : Primary provider with automatic cost tracking and unified API
8- - ** Multi-Provider Support** : OpenAI (DALL-E 3, GPT-Image-1) + Google Gemini (Imagen 3.0, Flash)
9- - ** Dynamic Model Discovery** : Auto-loads available models from LiteLLM
10- - ** SSE Streaming** : Real-time progress updates during generation
11- - ** Flexible Responses** : JSON, SSE stream, or HTML preview
12- - ** Local Storage** : Images saved locally and served via static files
13- - ** Comprehensive API** : Full OpenAPI/Swagger documentation
14- - ** Production Ready** : Docker support, health checks, authentication
7+ - ** Image Generation** : Create images from text prompts
8+ - ** Image Editing** : Edit existing images with mask-based inpainting (OpenAI) or prompt-based editing (Gemini)
9+ - ** Multi-Provider** : OpenAI (DALL-E 3, GPT-Image-1) and Google Gemini
10+ - ** LiteLLM Integration** : Unified API with cost tracking
11+ - ** Dynamic Models** : Auto-discovers available models from LiteLLM
12+ - ** Multiple Response Formats** : URL, base64, or markdown
1513
1614## Quick Start
1715
@@ -62,51 +60,48 @@ docker-compose up -d
6260
6361# # API Examples
6462
65- # ## Generate Image (Standard)
63+ # ## Generate Image
6664
6765` ` ` bash
6866curl -X POST " http://localhost:8000/generate" \
6967 -H " Content-Type: application/json" \
7068 -d ' {
71- "prompt": "A serene mountain landscape at sunset",
72- "provider": "litellm",
69+ "prompt": "A mountain landscape at sunset",
7370 "model": "dall-e-3",
74- "aspect_ratio": "16:9",
75- "quality": "hd"
71+ "aspect_ratio": "16:9"
7672 }'
7773` ` `
7874
79- # ## Generate with SSE Streaming
75+ # ## Edit Image (Mask-based, OpenAI)
8076
8177` ` ` bash
82- curl -N " http://localhost:8000/generate-stream " \
83- -H " Content-Type: application/json " \
84- -d ' {
85- "prompt": "A futuristic city skyline",
86- "aspect_ratio": "9:16"
87- } '
78+ curl -X POST " http://localhost:8000/edit " \
79+ -F " image=@photo.png " \
80+ -F " mask=@mask.png " \
81+ -F " prompt=Replace the sky with a sunset " \
82+ -F " provider=openai " \
83+ -F " model=gpt-image-1 "
8884` ` `
8985
90- # ## Python Client
86+ # ## Edit Image (Prompt-based, Gemini)
9187
92- ` ` ` python
93- import requests
88+ ` ` ` bash
89+ curl -X POST " http://localhost:8000/edit" \
90+ -F " image=@photo.png" \
91+ -F " prompt=Make the background more colorful" \
92+ -F " provider=gemini"
93+ ` ` `
9494
95- response = requests.post(
96- " http://localhost:8000/generate" ,
97- json={
98- " prompt" : " A cute cat wearing sunglasses" ,
99- " provider" : " litellm" , # or "openai", "gemini"
100- " aspect_ratio" : " 1:1" ,
101- " n" : 1
102- }
103- )
95+ # ## Edit via URL Reference
10496
105- result = response.json ()
106- print(f" Image URL: {result['image_url']}" )
97+ ` ` ` bash
98+ curl -X POST " http://localhost:8000/edit" \
99+ -F " image_url=http://localhost:8000/images/abc123.png" \
100+ -F " prompt=Add a hat to the person" \
101+ -F " provider=gemini"
107102` ` `
108103
109- # ## List Available Models
104+ # ## List Models
110105
111106` ` ` bash
112107curl " http://localhost:8000/models"
@@ -136,16 +131,19 @@ GEMINI_API_KEY=...
136131
137132# ## OpenAI
138133
139- - ** dall-e-3** : HD quality, multiple aspect ratios, n=1 only
140- - ** gpt-image-1** : Newest model, multiple sizes
141- - ** dall-e-2** : Square only, fast generation
134+ | Model | Generation | Editing | Notes |
135+ | -------| ------------| ---------| -------|
136+ | dall-e-3 | Yes | No | HD quality, multiple aspect ratios |
137+ | gpt-image-1 | Yes | Yes (mask) | Fast, supports inpainting |
138+ | dall-e-2 | Yes | Yes (mask) | Square only |
142139
143140# ## Google Gemini
144141
145- - ** gemini-2.0-flash-preview-image-generation** : Fast generation
146- - ** imagen-3.0-generate-002** : High quality
142+ | Model | Generation | Editing | Notes |
143+ | -------| ------------| ---------| -------|
144+ | gemini-2.0-flash-preview-image-generation | Yes | Yes (prompt) | Fast, prompt-based editing |
147145
148- See [CONFIGURATION.md](CONFIGURATION.md) for detailed model capabilities .
146+ See [CONFIGURATION.md](CONFIGURATION.md) for details .
149147
150148# # Open WebUI Integration
151149
@@ -161,20 +159,21 @@ For admin/global tools, configure in Admin Settings with server-accessible URL.
161159
162160# ## Image Generation
163161
164- - ` POST /generate` - Generate image (JSON response)
165- - ` POST /generate-stream` - Generate with SSE progress
166- - ` POST /generate-preview` - Generate with HTML preview
162+ - ` POST /generate` - Generate image from prompt
163+
164+ # ## Image Editing
165+
166+ - ` POST /edit` - Edit existing image (supports file upload or URL reference)
167167
168- # ## Model Management
168+ # ## Models
169169
170170- ` GET /models` - List available models
171171- ` POST /models/refresh` - Refresh model list from LiteLLM
172172
173- # ## Health & Info
173+ # ## Info
174174
175175- ` GET /health` - Health check + provider status
176- - ` GET /` - API information
177- - ` GET /docs` - Interactive API documentation
176+ - ` GET /docs` - API documentation
178177
179178# # Configuration
180179
@@ -200,36 +199,19 @@ With coverage:
200199pytest --cov=app --cov-report=html
201200` ` `
202201
203- # # Development
202+ # # Project Structure
204203
205- Project structure:
206-
207- ` ` ` txt
204+ ```
208205app/
209- ├── main.py # FastAPI application
210- ├── core/ # Configuration & utilities
211- ├── api/routes/ # API endpoints
212- ├── schemas/ # Pydantic models
213- ├── services/ # Business logic
214- └── utils/ # Helpers
215-
216- tests/ # Test suite
206+ ├── main.py # FastAPI app
207+ ├── core/ # Config, security
208+ ├── api/routes/ # Endpoints (generate, edit, models, health)
209+ ├── schemas/ # Request/response models
210+ └── services/ # Provider integrations
211+
212+ tests/ # Tests
217213```
218214
219215## License
220216
221217MIT
222-
223- # # Contributing
224-
225- Contributions welcome! Please ensure:
226-
227- - Tests pass (` pytest` )
228- - Code follows project style
229- - Documentation updated
230-
231- # # Support
232-
233- - Issues: GitHub Issues
234- - Docs: ` /docs` endpoint
235- - Health: ` /health` endpoint
0 commit comments