> ## 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.

# FLUX.2

> Black Forest Labs' FLUX.2 dev is the next-generation text-to-image diffusion transformer, with improved prompt adherence and detail.

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

Black Forest Labs' FLUX.2 dev is the next-generation text-to-image diffusion transformer, with improved prompt adherence and detail.

## 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**

> [tab] macOS or Linux
>
> ```bash Terminal theme={"system"}
> brew tap basetenlabs/baseten
> brew trust --formula basetenlabs/baseten/baseten
> brew install baseten
> ```

> [tab] 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.

> [tab] Lossless
>
> > [card] Hardware
> >
> > H100
>
> > [card] Engine
> >
> > Baseten 1.2
>
> ## Write the config
>
> Create and move into the project directory:
>
> ```sh theme={"system"}
> mkdir flux2-dev && cd flux2-dev
> ```
>
> Then create a file named `config.yaml` and paste the following:
>
> ```yaml config.yaml theme={"system"}
> model_name: "model:flux2-dev preset:lossless"
>
> base_image:
>   image: baseten/qwen-image-2512-h100:v1.2
>
> weights:
>   - source: hf://black-forest-labs/FLUX.2-dev@26afe3a78bb242c0a8bb181dcc8937bb16e5c66c
>     mount_location: /app/model_cache/FLUX.2-dev
>     auth_secret_name: hf_access_token
>     ignore_patterns:
>       - flux2-dev.safetensors
>
> 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:
>   repo_id: black-forest-labs/FLUX.2-dev
>   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"
>     response_format: "b64_json"
>     num_inference_steps: 50
>     guidance_scale: 1.0
>
> resources:
>   accelerator: H100 # B200 also supported
>   use_gpu: true
>
> secrets:
>   - hf_access_token
>
> 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 "flux2-dev"...
> Uploading model...
> Uploaded model in 0s
> ✨ Model flux2-dev was successfully pushed ✨
>
>   Model:       flux2-dev (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.
>
> > [tab] 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))
> > ```
>
> > [tab] 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))
> > ```
>
> > [tab] 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
> > ```

> [tab] Lossy
>
> FLUX.2 dev with attention caching enabled. Roughly 2× speedup with minor perceptual loss.
>
> > [card] Hardware
> >
> > H100
>
> > [card] Engine
> >
> > Baseten 1.2
>
> ## Write the config
>
> Create and move into the project directory:
>
> ```sh theme={"system"}
> mkdir flux2-dev-lossy && cd flux2-dev-lossy
> ```
>
> Then create a file named `config.yaml` and paste the following:
>
> ```yaml config.yaml theme={"system"}
> model_name: "model:flux2-dev preset:lossy"
>
> base_image:
>   image: baseten/qwen-image-2512-h100:v1.2
>
> weights:
>   - source: hf://black-forest-labs/FLUX.2-dev
>     mount_location: /app/model_cache/FLUX.2-dev
>     auth_secret_name: hf_access_token
>     ignore_patterns:
>       - flux2-dev.safetensors
>
> 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: black-forest-labs/FLUX.2-dev
>   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"
>     response_format: "b64_json"
>     num_inference_steps: 50
>     guidance_scale: 1.0
>
> resources:
>   accelerator: H100 # B200 also supported
>   use_gpu: true
>
> secrets:
>   - hf_access_token
>
> 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 "flux2-dev-lossy"...
> Uploading model...
> Uploaded model in 0s
> ✨ Model flux2-dev-lossy was successfully pushed ✨
>
>   Model:       flux2-dev-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.
>
> > [tab] 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))
> > ```
>
> > [tab] 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))
> > ```
>
> > [tab] 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

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

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