Commit 65ab272
committed
[Feature] Add OpenAI DALL-E compatible image generation API
Builds on @fake0fan's diffusion online serving implementation to provide
a production-ready, OpenAI-compatible image generation API. Implements
the DALL-E /v1/images/generations and /v1/images/edits endpoints with
full async support and proper error handling.
**OpenAI DALL-E API Compatibility:**
- `/v1/images/generations` - Text-to-image generation
- `/v1/images/edits` - Image editing with text prompts
- Full compatibility with OpenAI Python SDK
- Request/response formats match DALL-E specification
**Unified Async Server:**
- Single `vllm serve <model> --omni` command for all diffusion models
- Async AsyncOmniDiffusion engine with thread-pool execution
- Exposes both DALL-E endpoints and /v1/chat/completions
- Automatic model type detection (diffusion vs chat)
**Model Support:**
- Qwen/Qwen-Image (text-to-image with true CFG)
- Tongyi-MAI/Z-Image-Turbo (fast generation, ~9 steps)
- Qwen/Qwen-Image-Edit (image editing)
- Model profiles for per-model defaults and constraints
**Features:**
- Pydantic validation for all request parameters
- Comprehensive error handling with proper HTTP status codes
- Model field validation (request must match server)
- Empty prompt validation
- Response format validation (only b64_json supported)
- File upload validation (size, type, max 4MB)
- Prompt logging at debug level (security-conscious)
**Added:**
- image_api_utils.py - Shared helper functions (parse_size, encode_image, etc.)
- image_model_profiles.py - Model-specific configurations and constraints
- protocol/images.py - Pydantic models for requests/responses
- DALL-E endpoints in api_server.py (/v1/images/generations, /v1/images/edits)
- Comprehensive test suite (38 tests)
- Documentation and example client
**Modified:**
- api_server.py - Integrated DALL-E endpoints with async support
- pipeline_qwen_image_edit.py - Fixed duplicate methods, dimension unpacking, parameter naming
**Start server:**
```bash
vllm serve Qwen/Qwen-Image --omni --port 8000
```
**Generate image:**
```bash
curl -X POST http://localhost:8000/v1/images/generations \
-H "Content-Type: application/json" \
-d '{"prompt": "a cat on a laptop", "size": "1024x1024"}'
```
**Edit image:**
```bash
curl -X POST http://localhost:8000/v1/images/edits \
-F "[email protected]" \
-F "prompt=make the sky blue"
```
**OpenAI SDK:**
```python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")
response = client.images.generate(
prompt="a sunset over mountains",
size="1024x1024"
)
```
Testing available in:
```bash
pytest tests/entrypoints/openai/test_image_server.py -v
```
Built on @fake0fan's excellent diffusion online serving work (commits
e482de0, 003e8f3). This PR adds the DALL-E compatible API layer with
full validation, error handling, and production-ready features.
Signed-off-by: dougbtv <[email protected]>1 parent 003e8f3 commit 65ab272
14 files changed
Lines changed: 2556 additions & 56 deletions
File tree
- .buildkite/scripts
- docs
- examples/online_serving/image_generation
- tests/entrypoints
- openai
- vllm_omni
- diffusion/models/qwen_image
- entrypoints/openai
- protocol
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
0 commit comments