OpenAPI server for AI image generation and editing. Supports LiteLLM proxy (for cost tracking) and direct API access to OpenAI and Google Gemini.
- Image Generation: Create images from text prompts
- Image Editing: Edit existing images with mask-based inpainting (OpenAI) or prompt-based editing (Gemini)
- Multi-Provider: OpenAI (GPT-Image-1.5, GPT-Image-1) and Google Gemini
- LiteLLM Integration: Unified API with cost tracking
- Open WebUI Integration: Auto-upload images to Open WebUI's file storage
- Dynamic Models: Auto-discovers available models from LiteLLM
- Clone and configure:
git clone <your-repo>
cd openapi-image-gen
cp .env.example .env
# Edit .env with your API keys- Start the server:
docker-compose up -d- Access the API:
- API Docs: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
-
Install dependencies:
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt
-
Configure environment:
cp .env.example .env # Edit .env with your configuration -
Run the server:
uvicorn app.main:app --reload
curl -X POST "http://localhost:8000/generate" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A mountain landscape at sunset",
"model": "gpt-image-1",
"aspect_ratio": "16:9"
}'curl -X POST "http://localhost:8000/edit" \
-F "image=@photo.png" \
-F "mask=@mask.png" \
-F "prompt=Replace the sky with a sunset" \
-F "provider=openai" \
-F "model=gpt-image-1"curl -X POST "http://localhost:8000/edit" \
-F "image=@photo.png" \
-F "prompt=Make the background more colorful" \
-F "provider=gemini"curl -X POST "http://localhost:8000/edit" \
-F "image_url=http://localhost:8000/images/abc123.png" \
-F "prompt=Add a hat to the person" \
-F "provider=gemini"curl "http://localhost:8000/models"LiteLLM provides unified access, cost tracking, and rate limiting:
LITELLM_BASE_URL=http://litellm:4000
LITELLM_API_KEY=your-key # OptionalConfigure direct access for fallback when LiteLLM is unavailable:
OPENAI_API_KEY=sk-...
GEMINI_API_KEY=...LiteLLM doesn't support all provider features. Enable DIRECT_PROVIDER_FALLBACK to automatically use the native provider API when needed:
DIRECT_PROVIDER_FALLBACK=true
GEMINI_API_KEY=... # Required for Gemini fallbackCurrently applies to:
- Gemini aspect ratios: 16:9, 9:16, 4:3, 3:4 (LiteLLM only supports 1:1)
| Model | Generation | Editing | Notes |
|---|---|---|---|
| gpt-image-1.5 | Yes | Yes (mask) | Latest, quality: auto/high/medium/low |
| gpt-image-1 | Yes | Yes (mask) | Fast, supports inpainting |
| gpt-image-1-mini | Yes | Yes (mask) | Cost-efficient variant |
| Yes | No | Deprecated — shutting down May 12, 2026 | |
| Yes | Yes (mask) | Deprecated — shutting down May 12, 2026 |
| Model | Generation | Editing | Notes |
|---|---|---|---|
| gemini-2.5-flash-image | Yes | Yes (prompt) | Fast, wide aspect ratio support |
| gemini-3-pro-image-preview | Yes | Yes (prompt) | Preview, up to 4K resolution |
| Yes | Yes (prompt) | Deprecated — shutting down March 31, 2026 |
See CONFIGURATION.md for details.
- In Open WebUI, go to Settings > Tools
- Add new OpenAPI server:
- URL:
http://your-server:8000/openapi.json - Name: Image Generation
- URL:
- Tools will appear automatically in chat interface
For admin/global tools, configure in Admin Settings with server-accessible URL.
For the best experience (images display natively in chat with download/save):
- Generate an API key in Open WebUI: Settings > Account > API Keys
- Configure in
.env:
OPENWEBUI_MODE=true
OPENWEBUI_BASE_URL=http://open-webui:3000
OPENWEBUI_API_KEY=your-owui-api-keyImages are uploaded directly to Open WebUI's file storage and displayed inline, just like the built-in image generation.
Without OPENWEBUI_BASE_URL/OPENWEBUI_API_KEY, falls back to base64 HTMLResponse (iframe display).
POST /generate- Generate image from prompt
POST /edit- Edit existing image (supports file upload or URL reference)
GET /models- List available modelsPOST /models/refresh- Refresh model list from LiteLLM
GET /health- Health check + provider statusGET /docs- API documentation
See CONFIGURATION.md for complete configuration guide including:
- Environment variables
- Model capabilities
- Provider setup
- Authentication
- Storage options
Run tests:
pytestWith coverage:
pytest --cov=app --cov-report=htmlapp/
├── main.py # FastAPI app
├── core/ # Config, security
├── api/routes/ # Endpoints (generate, edit, models, health)
├── schemas/ # Request/response models
└── services/ # Provider integrations
tests/ # Tests
MIT