Skip to content

Commit 65ab272

Browse files
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/simple_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ VENV_PYTHON="${VENV_DIR}/bin/python"
5050
"${UV_BIN}" pip install --python "${VENV_PYTHON}" vllm==0.11.0
5151
"${UV_BIN}" pip install --python "${VENV_PYTHON}" -e ".[dev]"
5252
"${VENV_PYTHON}" -m pytest -v -s tests/test_omni_llm.py
53+
"${VENV_PYTHON}" -m pytest -v -s tests/entrypoints/openai/test_image_server.py

0 commit comments

Comments
 (0)