> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Qwen-Image

> Alibaba's Qwen-Image is a multimodal diffusion transformer for text-to-image generation, with strong bilingual (English and Chinese) text rendering.

[Text-to-image](https://docs.baseten.co/examples/models/capabilities/text-to-image)

Alibaba's Qwen-Image is a multimodal diffusion transformer for text-to-image generation, with strong bilingual (English and Chinese) text rendering.

## Setup

Install the Baseten CLI and sign in, then install the client library for the tab you'll use: `requests` for the Python tab, or the OpenAI SDK for the OpenAI tab.

**Install and sign in to Baseten**

**macOS or Linux**

```bash Terminal theme={"system"}
brew tap basetenlabs/baseten
brew trust --formula basetenlabs/baseten/baseten
brew install baseten
```

**Windows**

Download and extract the Windows archive for the latest Baseten CLI release:

```powershell Terminal theme={"system"}
$release = Invoke-RestMethod https://api.github.com/repos/basetenlabs/baseten-cli/releases/latest
$asset = $release.assets | Where-Object { $_.name -like "*_windows_amd64.zip" }
Invoke-WebRequest $asset.browser_download_url -OutFile baseten.zip
Expand-Archive -Force baseten.zip .
```

Move `baseten.exe` to a directory on your `PATH`.

For other platforms or a specific version, see the [Baseten CLI install reference](https://docs.baseten.co/reference/cli/baseten/overview.md#install).

```sh theme={"system"}
baseten auth login
```

**Install requests**

```sh theme={"system"}
uv pip install requests
```

**Install the OpenAI SDK**

```sh theme={"system"}
uv pip install openai
```

To install without Homebrew, see the [Baseten CLI install reference](https://docs.baseten.co/reference/cli/baseten/overview.md#install).

This variant ships in 2 presets tuned for different goals: **Lossless** for maximum visual fidelity, and **Lossy** for faster generation with minor perceptual trade-offs. Pick the tab that matches your workload.

**Lossless**

> **Hardware**
>
> H100

> **Engine**
>
> Baseten 1.2

## Write the config

Create and move into the project directory:

```sh theme={"system"}
mkdir qwen-image && cd qwen-image
```

Then create a file named `config.yaml` and paste the following:

```yaml config.yaml theme={"system"}
model_name: "model:qwen-image preset:lossless"

base_image:
  image: baseten/qwen-image-2512-h100:v1.2

weights:
  - source: hf://Qwen/Qwen-Image-2512@25468b98e3276ca6700de15c6628e51b7de54a26
    mount_location: /app/model_cache/qwen-image-2512

docker_server:
  start_command: bash /app/data/start_sglang_server.sh
  readiness_endpoint: /health_generate
  liveness_endpoint: /health_generate
  predict_endpoint: /v1/images/generations
  server_port: 8000

environment_variables:
  SGLANG_WARMUP_SIZE_ON_INIT: "1024x1024"

model_metadata:
  output_media:
    - json_path: "data[*].b64_json"
      media_type: "image/png"
      encoding: "base64"
      label: "Generated Image"

  example_model_input:
    prompt: "A cat holding up a sign that reads 'Hello, world!'"
    size: "1024x1024"
    guidance_scale: 1.0
    num_inference_steps: 25
    response_format: "b64_json"

resources:
  accelerator: H100 # B200 also supported
  use_gpu: true


runtime:
  health_checks:
    # Reduced delays since model weights are now cached
    startup_threshold_seconds: 600   # 10 minutes (was 20)
    restart_threshold_seconds: 300      # 5 minutes
    stop_traffic_threshold_seconds: 300 # 5 minutes
```

## Deploy

Push the config to Baseten with the Baseten CLI, or with the Truss CLI if you prefer it:

```sh Baseten CLI theme={"system"}
baseten model push
```

```sh Truss CLI theme={"system"}
uvx truss push
```

You should see output similar to:

```output theme={"system"}
Pushing model "qwen-image"...
Uploading model...
Uploaded model in 0s
✨ Model qwen-image was successfully pushed ✨

  Model:       qwen-image (abc1d2ef)
  Deployment:  xyz123
  Environment: production

🪵 View logs:
   deployment:   baseten model deployment logs --model-id abc1d2ef --deployment-id xyz123
   environment:  baseten model environment logs --model-id abc1d2ef --environment production  (once deployed)
   app:          https://app.baseten.co/models/abc1d2ef/logs/xyz123

🚀 Invoke your model:
   URL:  https://model-abc1d2ef.api.baseten.co/deployment/xyz123/predict
   CLI:  baseten model predict --model-id abc1d2ef
```

`baseten model push` prints your **model ID** (`abc1d2ef` in the example). The examples below use it wherever you see `{model_id}`, and read your API key from the `BASETEN_API_KEY` environment variable.

## Call the model

Use the `/v1/images/generations` endpoint to generate your model's images.

The deployment returns the generated image as base64-encoded bytes. Decode the response to write the image to disk. The `size` parameter sets the output resolution in pixels.

**Python**

```python main.py theme={"system"}
import base64
import os
import requests

response = requests.post(
    "https://model-{model_id}.api.baseten.co/environments/production/sync/v1/images/generations",
    headers={"Authorization": f"Bearer {os.environ['BASETEN_API_KEY']}"},
    json={
        "prompt": "A cat holding up a sign that reads 'Hello, world!'",
        "size": "1024x1024",
        "response_format": "b64_json",
    },
)

image_b64 = response.json()["data"][0]["b64_json"]
with open("output.png", "wb") as f:
    f.write(base64.b64decode(image_b64))
```

**OpenAI**

```python main.py theme={"system"}
import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BASETEN_API_KEY"],
    base_url="https://model-{model_id}.api.baseten.co/environments/production/sync/v1",
)

image = client.images.generate(
    prompt="A cat holding up a sign that reads 'Hello, world!'",
    size="1024x1024",
    response_format="b64_json",
)

with open("output.png", "wb") as f:
    f.write(base64.b64decode(image.data[0].b64_json))
```

**cURL**

```sh theme={"system"}
curl -s https://model-{model_id}.api.baseten.co/environments/production/sync/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $BASETEN_API_KEY" \
  -d '{"prompt": "A cat holding up a sign that reads 'Hello, world!'", "size": "1024x1024", "response_format": "b64_json"}' \
  | jq -r '.data[0].b64_json' | base64 --decode > output.png
```

**Lossy**

Qwen-Image with speed optimizations. Roughly 2× faster generation with minor perceptual loss.

> **Hardware**
>
> H100

> **Engine**
>
> Baseten 1.2

## Write the config

Create and move into the project directory:

```sh theme={"system"}
mkdir qwen-image-lossy && cd qwen-image-lossy
```

Then create a file named `config.yaml` and paste the following:

```yaml config.yaml theme={"system"}
model_name: "model:qwen-image preset:lossy"

base_image:
  image: baseten/qwen-image-2512-h100:v1.2

weights:
  - source: hf://Qwen/Qwen-Image-2512@25468b98e3276ca6700de15c6628e51b7de54a26
    mount_location: /app/model_cache/qwen-image-2512

docker_server:
  start_command: bash /app/data/start_sglang_server.sh
  readiness_endpoint: /health_generate
  liveness_endpoint: /health_generate
  predict_endpoint: /v1/images/generations
  server_port: 8000

environment_variables:
  SGLANG_WARMUP_SIZE_ON_INIT: "1024x1024"
  SGLANG_CACHE_DIT_ENABLED: "true"
  SGLANG_CACHE_DIT_WARMUP: "2"
  SGLANG_CACHE_DIT_TAYLORSEER: "true"
  SGLANG_CACHE_DIT_FN: "2"
  SGLANG_CACHE_DIT_BN: "0"

model_metadata:
  repo_id: Qwen/Qwen-Image-2512
  output_media:
    - json_path: "data[*].b64_json"
      media_type: "image/png"
      encoding: "base64"
      label: "Generated Image"

  example_model_input:
    prompt: "A cat holding up a sign that reads 'Hello, world!'"
    size: "1024x1024"
    guidance_scale: 1.0
    num_inference_steps: 25
    response_format: "b64_json"

resources:
  instance_type: H100 # B200 also supported

runtime:
  health_checks:
    # Reduced delays since model weights are now cached
    startup_threshold_seconds: 600   # 10 minutes (was 20)
    restart_threshold_seconds: 300      # 5 minutes
    stop_traffic_threshold_seconds: 300 # 5 minutes
```

## Deploy

Push the config to Baseten with the Baseten CLI, or with the Truss CLI if you prefer it:

```sh Baseten CLI theme={"system"}
baseten model push
```

```sh Truss CLI theme={"system"}
uvx truss push
```

You should see output similar to:

```output theme={"system"}
Pushing model "qwen-image-lossy"...
Uploading model...
Uploaded model in 0s
✨ Model qwen-image-lossy was successfully pushed ✨

  Model:       qwen-image-lossy (abc1d2ef)
  Deployment:  xyz123
  Environment: production

🪵 View logs:
   deployment:   baseten model deployment logs --model-id abc1d2ef --deployment-id xyz123
   environment:  baseten model environment logs --model-id abc1d2ef --environment production  (once deployed)
   app:          https://app.baseten.co/models/abc1d2ef/logs/xyz123

🚀 Invoke your model:
   URL:  https://model-abc1d2ef.api.baseten.co/deployment/xyz123/predict
   CLI:  baseten model predict --model-id abc1d2ef
```

`baseten model push` prints your **model ID** (`abc1d2ef` in the example). The examples below use it wherever you see `{model_id}`, and read your API key from the `BASETEN_API_KEY` environment variable.

## Call the model

Use the `/v1/images/generations` endpoint to generate your model's images.

The deployment returns the generated image as base64-encoded bytes. Decode the response to write the image to disk. The `size` parameter sets the output resolution in pixels.

**Python**

```python main.py theme={"system"}
import base64
import os
import requests

response = requests.post(
    "https://model-{model_id}.api.baseten.co/environments/production/sync/v1/images/generations",
    headers={"Authorization": f"Bearer {os.environ['BASETEN_API_KEY']}"},
    json={
        "prompt": "A cat holding up a sign that reads 'Hello, world!'",
        "size": "1024x1024",
        "response_format": "b64_json",
    },
)

image_b64 = response.json()["data"][0]["b64_json"]
with open("output.png", "wb") as f:
    f.write(base64.b64decode(image_b64))
```

**OpenAI**

```python main.py theme={"system"}
import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BASETEN_API_KEY"],
    base_url="https://model-{model_id}.api.baseten.co/environments/production/sync/v1",
)

image = client.images.generate(
    prompt="A cat holding up a sign that reads 'Hello, world!'",
    size="1024x1024",
    response_format="b64_json",
)

with open("output.png", "wb") as f:
    f.write(base64.b64decode(image.data[0].b64_json))
```

**cURL**

```sh theme={"system"}
curl -s https://model-{model_id}.api.baseten.co/environments/production/sync/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $BASETEN_API_KEY" \
  -d '{"prompt": "A cat holding up a sign that reads 'Hello, world!'", "size": "1024x1024", "response_format": "b64_json"}' \
  | jq -r '.data[0].b64_json' | base64 --decode > output.png
```

## Next steps

> **[Call your model](https://docs.baseten.co/inference/calling-your-model.md)**
>
> Endpoint anatomy, authentication, and sync versus async inference

> **[Autoscaling](https://docs.baseten.co/deployment/autoscaling/overview.md)**
>
> Scale replicas with traffic, including scale to zero
