2025-12-19 06:11:54 +08:00
# Text-To-Image
2025-12-17 17:40:45 +08:00
2025-12-19 06:11:54 +08:00
Source <https://github.com/vllm-project/vllm-omni/tree/main/examples/online_serving/text_to_image>.
2025-12-17 17:40:45 +08:00
This example demonstrates how to deploy Qwen-Image model for online image generation service using vLLM-Omni.
## Start Server
### Basic Start
```bash
vllm serve Qwen/Qwen-Image --omni --port 8091
```
2026-01-10 19:02:32 +08:00
!!! note
If you encounter Out-of-Memory (OOM) issues or have limited GPU memory, you can enable VAE slicing and tiling to reduce memory usage, --vae-use-slicing --vae-use-tiling
2025-12-17 17:40:45 +08:00
### Start with Parameters
Or use the startup script:
```bash
bash run_server.sh
```
## API Calls
### Method 1: Using curl
```bash
# Basic text-to-image generation
bash run_curl_text_to_image.sh
# Or execute directly
curl -s http://localhost:8091/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "A beautiful landscape painting"}
],
"extra_body": {
"height": 1024,
"width": 1024,
"num_inference_steps": 50,
"true_cfg_scale": 4.0,
"seed": 42
}
2026-01-10 19:02:32 +08:00
}' | jq -r '.choices[0].message.content[0].image_url.url' | cut -d',' -f2- | base64 -d > output.png
2025-12-17 17:40:45 +08:00
```
### Method 2: Using Python Client
```bash
python openai_chat_client.py --prompt "A beautiful landscape painting" --output output.png
```
### Method 3: Using Gradio Demo
```bash
python gradio_demo.py
# Visit http://localhost:7860
```
## Request Format
2025-12-19 06:11:54 +08:00
### Simple Text Generation
2025-12-17 17:40:45 +08:00
```json
{
"messages" : [
{ "role" : "user" , "content" : "A beautiful landscape painting" }
]
}
```
### Generation with Parameters
Use `extra_body` to pass generation parameters:
```json
{
"messages" : [
{ "role" : "user" , "content" : "A beautiful landscape painting" }
],
"extra_body" : {
"height" : 1024 ,
"width" : 1024 ,
"num_inference_steps" : 50 ,
"true_cfg_scale" : 4.0 ,
"seed" : 42
}
}
```
### Multimodal Input (Text + Structured Content)
```json
{
"messages" : [
{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "A beautiful landscape painting" }
]
}
]
}
```
## Generation Parameters (extra_body)
2025-12-19 06:11:54 +08:00
| Parameter | Type | Default | Description |
| ------------------------ | ----- | ------- | ------------------------------ |
| `height` | int | None | Image height in pixels |
| `width` | int | None | Image width in pixels |
| `size` | str | None | Image size (e.g., "1024x1024") |
| `num_inference_steps` | int | 50 | Number of denoising steps |
| `true_cfg_scale` | float | 4.0 | Qwen-Image CFG scale |
| `seed` | int | None | Random seed (reproducible) |
| `negative_prompt` | str | None | Negative prompt |
| `num_outputs_per_prompt` | int | 1 | Number of images to generate |
2026-01-22 16:57:37 +08:00
| `--cfg-parallel-size` . | int | 1 | Number of GPUs for CFG parallelism |
2025-12-17 17:40:45 +08:00
## Response Format
```json
{
"id" : "chatcmpl-xxx" ,
"created" : 1234567890 ,
"model" : "Qwen/Qwen-Image" ,
"choices" : [{
"index" : 0 ,
"message" : {
"role" : "assistant" ,
"content" : [{
"type" : "image_url" ,
"image_url" : {
"url" : "data:image/png;base64,..."
}
}]
},
"finish_reason" : "stop"
}],
"usage" : { ... }
}
```
## Extract Image
```bash
# Extract base64 from response and decode to image
2026-01-10 19:02:32 +08:00
cat response.json | jq -r '.choices[0].message.content[0].image_url.url' | cut -d',' -f2- | base64 -d > output.png
2025-12-17 17:40:45 +08:00
```
## File Description
2025-12-19 06:11:54 +08:00
| File | Description |
| --------------------------- | ---------------------------- |
| `run_server.sh` | Server startup script |
| `run_curl_text_to_image.sh` | curl example |
| `openai_chat_client.py` | Python client |
| `gradio_demo.py` | Gradio interactive interface |
2025-12-17 17:40:45 +08:00
## Example materials
??? abstract "gradio_demo.py"
``````py
2025-12-19 06:11:54 +08:00
--8<-- "examples/online_serving/text_to_image/gradio_demo.py"
2025-12-17 17:40:45 +08:00
` `````
??? abstract "openai_chat_client.py"
` `````py
2025-12-19 06:11:54 +08:00
--8<-- "examples/online_serving/text_to_image/openai_chat_client.py"
2025-12-17 17:40:45 +08:00
` `````
??? abstract "run_curl_text_to_image.sh"
` `````sh
2025-12-19 06:11:54 +08:00
--8<-- "examples/online_serving/text_to_image/run_curl_text_to_image.sh"
2025-12-17 17:40:45 +08:00
` `````
??? abstract "run_server.sh"
` `````sh
2025-12-19 06:11:54 +08:00
--8<-- "examples/online_serving/text_to_image/run_server.sh"
2025-12-17 17:40:45 +08:00
` `````