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

> FLUX.1 recipes: 2 variants (dev, schnell), diffusion-transformer architecture.

<div className="capability-pills">
  <a href="/examples/models/capabilities/text-to-image" className="capability-pill">Text-to-image</a>
</div>

## Setup

To get started, sign into Baseten with Truss and then install the Python `requests` library.

<Columns cols={2}>
  <Column>
    **Sign in to Baseten**

    ```sh theme={"system"}
    uvx truss login --browser
    ```
  </Column>

  <Column>
    **Install requests**

    ```sh theme={"system"}
    uv pip install requests
    ```
  </Column>
</Columns>

Pick the model you want to deploy. Each tab is a self-contained recipe.

<Tabs>
  <Tab title="dev">
    [black-forest-labs/FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev) is a 12B-parameter diffusion transformer model.

    This preset serves FLUX.1 dev on H100 40GB, tuned for text-to-image throughput.

    <CardGroup cols={1}>
      <Card title="Hardware" icon="microchip">H100\_40GB</Card>
    </CardGroup>

    ## Write the config

    Create and move into the project directory:

    ```sh theme={"system"}
    mkdir flux1-dev-throughput && cd flux1-dev-throughput
    ```

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

    ```yaml config.yaml theme={"system"}
    external_package_dirs: []
    model_metadata:
      example_model_input: {"prompt": 'black forest gateau cake spelling out the words "FLUX DEV", tasty, food photography, dynamic shot'}
      repo_id: black-forest-labs/FLUX.1-dev
    model_name: "model:flux1-dev preset:throughput"
    python_version: py311
    requirements:
      - git+https://github.com/huggingface/diffusers.git@fc6a91e3834c35e57b398ad1c0d99f6f83557e04
      - transformers>=4.0.0,<5.0.0
      - accelerate
      - sentencepiece
      - protobuf
    weights:
      - source: "hf://black-forest-labs/FLUX.1-dev@main"
        mount_location: "/models/FLUX.1-dev"
        auth_secret_name: "hf_access_token"
    resources:
      accelerator: H100_40GB
      use_gpu: true
    secrets:
      hf_access_token: null
    system_packages:
      - ffmpeg
      - libsm6
      - libxext6
    ```

    ## Deploy

    Push the config to Baseten:

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

    You should see output similar to:

    ```text theme={"system"}
    ✨ Model flux1-dev-throughput was successfully pushed ✨
    🪵 View logs for your deployment at https://app.baseten.co/models/abcd1234/logs/wxyz5678
    ```

    Your **model ID** is the string after `/models/` in the logs URL (`abcd1234` in the example). Use it wherever you see `{model_id}` in the next section.

    ## Call the model

    Your deployment exposes `/predict`. Replace `{model_id}` with your model ID and make sure `BASETEN_API_KEY` is set.

    The deployment returns the generated image as base64-encoded bytes. Decode the response to write the image to disk.

    <Tabs>
      <Tab title="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/predict",
            headers={"Authorization": f"Bearer {os.environ['BASETEN_API_KEY']}"},
            json={"prompt": "black forest gateau cake spelling out the words \"FLUX DEV\", tasty, food photography, dynamic shot"},
        )

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

      <Tab title="cURL">
        ```sh theme={"system"}
        curl -s https://model-{model_id}.api.baseten.co/environments/production/sync/predict \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $BASETEN_API_KEY" \
          -d '{"prompt": "black forest gateau cake spelling out the words \"FLUX DEV\", tasty, food photography, dynamic shot"}' \
          | jq -r '.data' | base64 --decode > output.png
        ```
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="schnell">
    [black-forest-labs/FLUX.1-schnell](https://huggingface.co/black-forest-labs/FLUX.1-schnell) is a 12B-parameter diffusion transformer model.

    This preset serves FLUX.1 schnell on H100 40GB. The step-distilled model delivers the fastest FLUX image generation per dollar.

    <CardGroup cols={1}>
      <Card title="Hardware" icon="microchip">H100\_40GB</Card>
    </CardGroup>

    ## Write the config

    Create and move into the project directory:

    ```sh theme={"system"}
    mkdir flux1-schnell-throughput && cd flux1-schnell-throughput
    ```

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

    ```yaml config.yaml theme={"system"}
    external_package_dirs: []
    model_metadata:
      example_model_input: {"prompt": 'black forest gateau cake spelling out the words "FLUX SCHNELL", tasty, food photography, dynamic shot'}
      repo_id: black-forest-labs/FLUX.1-schnell
    model_name: "model:flux1-schnell preset:throughput"
    python_version: py311
    requirements:
      - git+https://github.com/huggingface/diffusers.git@fc6a91e3834c35e57b398ad1c0d99f6f83557e04
      - transformers>=4.0.0,<5.0.0
      - accelerate
      - sentencepiece
      - protobuf
      - b10-transfer
    weights:
      - source: "hf://black-forest-labs/FLUX.1-schnell@main"
        mount_location: "/models/FLUX.1-schnell"
        auth_secret_name: "hf_access_token"
    resources:
      accelerator: H100_40GB
      use_gpu: true
    secrets:
      hf_access_token: null
    system_packages:
      - ffmpeg
      - libsm6
      - libxext6
    ```

    ## Deploy

    Push the config to Baseten:

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

    You should see output similar to:

    ```text theme={"system"}
    ✨ Model flux1-schnell-throughput was successfully pushed ✨
    🪵 View logs for your deployment at https://app.baseten.co/models/abcd1234/logs/wxyz5678
    ```

    Your **model ID** is the string after `/models/` in the logs URL (`abcd1234` in the example). Use it wherever you see `{model_id}` in the next section.

    ## Call the model

    Your deployment exposes `/predict`. Replace `{model_id}` with your model ID and make sure `BASETEN_API_KEY` is set.

    The deployment returns the generated image as base64-encoded bytes. Decode the response to write the image to disk.

    <Tabs>
      <Tab title="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/predict",
            headers={"Authorization": f"Bearer {os.environ['BASETEN_API_KEY']}"},
            json={"prompt": "black forest gateau cake spelling out the words \"FLUX SCHNELL\", tasty, food photography, dynamic shot"},
        )

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

      <Tab title="cURL">
        ```sh theme={"system"}
        curl -s https://model-{model_id}.api.baseten.co/environments/production/sync/predict \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $BASETEN_API_KEY" \
          -d '{"prompt": "black forest gateau cake spelling out the words \"FLUX SCHNELL\", tasty, food photography, dynamic shot"}' \
          | jq -r '.data' | base64 --decode > output.png
        ```
      </Tab>
    </Tabs>
  </Tab>
</Tabs>
